XF 2.1 Xenforo Conditional Statement Syntax Question

My goal is to use the message_macro template to apply a special border to avatars based on if they are an administrator, moderator, or a regular user. I've tried it a million ways and I can't get it to stop it from yelling at me. Coding experience is very amateur so I apologize for what is probably a dumb question. How should the syntax be?

Code:
<xf:if is="{{ $xf.user.isMemberOf(3) }}">
                <div class="avatarHolder avatarHolderAdmin">

<xf:elseif is="{{ $xf.user.isMemberOf(4) }}">
                <div class="avatarHolder avatarHolderModerator">

            <xf:else>
                <div class="avatarHolder">
                </div>
</xf:else>
</xf:elseif>
</xf:if>

In theory line 1 checks to see if they are part of the admin group, if they are then admin avatar holder div is applied. Line 4 checks to see if the user is a member of the moderator group, if they are then it applies the moderator avatar holder rather than the admin one. Line 7 should say that if they are apart of any other group apply the regular avatar holder div.

My guess is I'm screwing up in closing out these statements, any ideas?
 
Last edited:
<xf:elseif is=""/> and <xf:else /> are self-closing tags. You'll need a slash at the end of the initial tag and then don't need the separate closing tag at all. E.g.:
HTML:
<xf:if is="">
  <!-- first condition is true -->
<xf:elseif is="" />
  <!-- second condition is true -->
<xf:else />
  <!-- neither first or second condition is true -->
</xf:if>

You may like to read through the template syntax page in the developer documentation (Else/Else-If tag section):

The example in the documentation also describes an alternate way for checking whether a user is an admin or moderator.
 
Any idea on how to check if a post was made by an admin/moderator/normal user then apply the conditions depending on which is true? Seems like what I have is it checks if the person viewing the page is staff or not and applies the condition based on that.

What I need is it checks if the user displayed in user_info for each post is staff or not and apply a border to their avatar in the post based on that. I was thinking I could do this based on jobTitle (so if there jobTitle is Administrator apply the border) but I have no idea how one would write that out in valid expression. Any suggestions?
 
$xf.visitor does mean the person viewing the page, yes. You'd just substitute this with the variable that corresponds with the message user in the template you're working with. In your original post you mentioned message_macros, so in this case the variable you want seems to be $user.
 
does one have any idea how i can achieve this logic...

if is not registered and is homepage{
show none
} else{
show this
}

i dont want to show ad banner on guest on the homepage only...
 
Top Bottom