I have used the following if check to hide/show content based on webrole in the past, and it has worked without issue, but recently I have found that it ignore the if and just shows the content...anyone had any issues with it?
Is there another statement besides "contains" to match perfectly against This Role Name?
{% if user.roles contains 'This Role Name' %}
<div class="example">SHOW THIS HTML CONTENT FOR This Role Name web roles</div>{% endif %}
*This post is locked for comments
Found the answer:
{% assign is_admin = user | has_role: 'Administrators' %}
{% if is_admin %}
User is an administrator.
{% endif %}
The issue is that when I get {{user.roles}} (Note the plural S) I get this back:
'''This RoleAnother RoleThis Role too'''
Which should be This Role, Another Role, This Role Too
Is there any way to get each role individually?
Hi Kphenix,
I have also observed that user role 'contains' in liquid template check for exact web role of user. It does not check for particular keyword like contains usually do.
Just a thought, if you have such requirement :
If portal user role contains 'abc' then perform action, for this you can first store the portal logged In user role in javascript variable (let say: var role = {{user.role}};) then check contains by "index of" , like we usually do in javascript string variable.
Example :
Var loggedinuserRole = {{user.role}};
If(loggedinuserRole.indexOf("abc") > -1)
{
<div class="example">SHOW THIS HTML CONTENT FOR This Role Name web roles</div>
}
Please mark it verified. If it helps.
Cheers
Arpit
Yes, it's not a single item, there are multiple web roles, so that doesn't work
Did you try:
{% if user.roles == 'This Role Name' %}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156