Please help me get an If Then statement correct to block tabs for Guests

Jamie

Well-known member
#1
I have the shoutbox installed and since guests can't use it I would like to just hide the tab for anyone that can't use it.

So what is the code I am looking for?

<if guest>
Show Guest menu
<else />
Show Member menu
</if>


Thanks!
Jamie
 

Jamie

Well-known member
#2
Figured it out.. In case anyone else is wondering, here is an example I was playing around with to see if it worked.

For Guest, the home tab is called Continue and for Members it's called Home.. I know, silly but it was a quick exercise to see how it worked. :)

<xen:if is="{$visitor.user_id}">
<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase continue}</a></li>
<xen:else />
<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase home}</a></li>
</xen:if>
 

Jake Bunce

XenForo moderator
Staff member
#3
For Guest, the home tab is called Continue and for Members it's called Home.

...

<xen:if is="{$visitor.user_id}">
<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase continue}</a></li>
<xen:else />
<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase home}</a></li>
</xen:if>
Based on that description I think you got the condition reversed. The first block is true for logged in users. The second block is true for guests.
 

Jamie

Well-known member
#4
Oh.. i thought this line: <xen:if is="{$visitor.user_id}"> was saying if this user IS a visitor... no?

Jamie
/learning curve here.. :)
 

Jake Bunce

XenForo moderator
Staff member
#5
Oh.. i thought this line: <xen:if is="{$visitor.user_id}"> was saying if this user IS a visitor... no?
Well, you are accessing the $visitor[] array, but you are specifically checking the user_id. Only logged in users have user_ids.

The direct condition to check for guests is:

Code:
<xen:if is="!{$visitor.user_id}">
	FOR GUESTS
</xen:if>
This reads, "if the user does not have a user_id."
 

Jamie

Well-known member
#6
Ah, ok. Thanks for your help! btw, how did you wrap that in the blue code tag? I looked but couldn't see a BBcode tag for that and ended up with smiles in my example. :)

Jamie
 

Jeremy P

Well-known member
#7
That condition will determine if the person currently visiting the page has a user id, which only logged in users would.. so yes it is reversed.

EDIT: Ahh too late.
 
Top