web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Liquid Web Role if statement

(0) ShareShare
ReportReport
Posted on by 4

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

I have the same question (0)
  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Did you try:

    {% if user.roles == 'This Role Name' %}

  • kphenix Profile Picture
    4 on at

    Yes, it's not a single item, there are multiple web roles, so that doesn't work

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at

    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

  • kphenix Profile Picture
    4 on at

    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?

  • Verified answer
    kphenix Profile Picture
    4 on at

    Found the answer:

    {% assign is_admin = user | has_role: 'Administrators' %}

    {% if is_admin %}

     User is an administrator.

    {% endif %}

  • vcd_planet Profile Picture
    2 on at
    Thank you @kphenix! I spent 2 hours with co-pilot and other articles. Your post saved me!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans