Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Liquid Web Role if statement

Posted on by 2

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

  • vcd_planet Profile Picture
    vcd_planet 2 on at
    Liquid Web Role if statement
    Thank you @kphenix! I spent 2 hours with co-pilot and other articles. Your post saved me!
  • Verified answer
    kphenix Profile Picture
    kphenix 2 on at
    RE: Liquid Web Role if statement

    Found the answer:

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

    {% if is_admin %}

     User is an administrator.

    {% endif %}

  • kphenix Profile Picture
    kphenix 2 on at
    RE: Liquid Web Role if statement

    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?

  • Suggested answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Liquid Web Role if statement

    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
    kphenix 2 on at
    RE: Liquid Web Role if statement

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

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Liquid Web Role if statement

    Did you try:

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans