• 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

Jake Bunce

Well-known 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>
 
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.
 
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.

It's the author of the post, not of the thread.
 
I want to show something to admin and mod group, so how can I only allow both groups?

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.
 
Is there a way to do the inverse? Thus, where user is NOT a member of group?

Thanks,

Mike
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>
 
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>
 
Top Bottom