User Documentation

User:Has_Role template tag

The User:Has_Role tag allows you to check if a current user or current user's group has a specific User Role or set of roles assigned to them. It's a great way to restrict blocks of content, forms, admin tools, etc to users with sufficient privileges.

{exp:user:has_role} content {/exp:user:has_role}

Parameters

roles=

roles="honey_dippers|bench_warmers"

This parameter tells the User:Has_Role tag which roles to check against the current user. Specify the role short names that you would like to check on. By default, it will check to see if the user has any of the roles in this parameter. If you want ALL roles to be matched against the current user, use the match_all parameter.

match_all=

match_all="yes"

By default, the roles parameter will check to see if the user has any of the roles specified in the parameter. If you want ALL roles to be matched against the current user, use this parameter with a value of yes.

Conditionals

{has_roles}

{if has_roles}
    You have sufficient privileges to view this content.
{if:else}
    Sorry, you are not allowed to view this content.
{/if}

This conditional will display its contents if the current user's role(s) match the role(s) specified for this template tag.

Examples

The simple example below shows you how to show different content to users who do and do not have the listed roles required:

{exp:user:has_role
    roles="honey_dippers|bench_warmers"
    match_all="yes"
}
    {if has_roles}
        <h3>Super Secret Content!</h3>
        <p>I've always thought that baseball card bubble gum was nasty.</p>
    {if:else}
        <h3>(╯‵Д′)╯彡┻━┻</h3>
        <p>You are not privy to my high-end rhetoric.</p>
    {/if}
{/exp:user:has_role}

Support

Having problems setting up and/or using User? Support is offered from 10am to 4pm EST weekdays. Send us an email at help@eeharbor.com and we will respond as quickly as we can.