1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Usergroup Checking In The Templates

Discussion in 'Tips and Guides [Archive]' started by Jake Bunce, Dec 19, 2010.

  1. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This is a common request. A new template helper for group checking was recently added. This checks all of a user's groups, including secondary groups. This is useful if you want to display something in a template for members of a specific group.

    You can use this code in the templates to display something for members of the specified user_group_id:

    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, 4}">
    	stuff to display for members of user_group_id 4
    </xen:if>
    
    In the above example we are checking if the current logged in user ($visitor) is a member of user_group_id 4.

    You can pass in any user record. For example, the message_user_info template contains the template code for the author box in posts. The user record for the author in that template is $user. So, for example, if we want to display something in the author box if the post author is a member of user_group_id 4 then we can use this:

    Code:
    <xen:if is="{xen:helper ismemberof, $user, 4}">
    	stuff to display for members of user_group_id 4
    </xen:if>
    
     
    maszd, majafy, Aceros and 10 others like this.
  2. Allan

    Allan Well-Known Member

    Interesting thank you Jake ;)
     
  3. CFodder

    CFodder Well-Known Member

    How would we do this if we want to check for multiple groups, I have tried:

    But it doesn't seem to work??
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    It doesn't do multiple groups.
     
  5. CFodder

    CFodder Well-Known Member

    OK, thanks Jake :)
     
  6. matthewalan

    matthewalan Active Member

    I just got redirected to this, and had a question about this. I am interested in the second part, the $user part. You said that it affects the author, does that mean the author of a post, or the author of the original thread? Because I am interested in changing the postbit for my staff members to a different color, and would like to have it affect all the posts in a topic.
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    It's the author of the post, not of the thread.
     
  8. Veer

    Veer Well-Known Member

    I want to show something to admin and mod group, so how can I only allow both groups?
     
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Use code like this:

    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, 3} OR {xen:helper ismemberof, $visitor, 4}">
    	stuff to display for members of user_group_id 3 and 4
    </xen:if>
    
    3 and 4 are the ids for the default admin and mod groups.
     
    The8thLegion and Veer like this.
  10. Amphicar770

    Amphicar770 Active Member

    Is there a way to do the inverse? Thus, where user is NOT a member of group?

    Thanks,

    Mike
     
  11. James

    James Well-Known Member

    Put an exclamation mark before the condition:
    Code:
    <xen:if is="!{xen:helper ismemberof, $visitor, 4}">
    	stuff to display for members of user_group_id 4
    </xen:if>
    
     
  12. James

    James Well-Known Member

    Just to add, you now can check for multiple usergroups using this:
    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, 2, 3, 4}">
    stuff to display for usergroups 2, 3 and 4.
    </xen:if>
    
     
    thedude and Trekkan like this.
  13. Brogan

    Brogan XenForo Moderator Staff Member

  14. DRE

    DRE Well-Known Member

    Thread should be stickied.
     

Share This Page