Calum Harrison logo
  • Home 
  • Tags 
  • About Me 
  1. Home
  2. Posts
  3. Using Liquid and Web Roles together in Power Pages

Using Liquid and Web Roles together in Power Pages

Posted on May 24, 2025  (Last modified on May 25, 2025) • 2 min read • 284 words
Power Pages   Liquid   Security   Web Roles  
Power Pages   Liquid   Security   Web Roles  
Share via
Calum Harrison
Link copied to clipboard

On this page
  • Example has_role
  • Example contains
  • Debug tip
  • Conclusion
Using Liquid and Web Roles together in Power Pages

Do you want to only show or apply something in Power Pages to someone who has a particular web role in Liquid?

You could use this technique to show some relevant text on a page or even use it as a extra layer of security.

Example has_role  

The has_role method allows you to check for a individual role. In the example below, it checks if the user logged in either has the “Manager” or “Director” web role. If they do, then it would show some text relevant to them.

{% if user %}

  {% assign manager = user | has_role: 'Manager' %}
  {% assign director = user | has_role: 'Director' %}

  {% if manager or director %}
    <p> Welcome to the management section... </p>
  {% endif %}

{% endif %}

Example contains  

The contains method allows you to check for multiple roles. In the example below, it shows the management section to anyone who’s web role contains “manager”.

{% if user %}

  {% assign userRoles = user.roles | downcase %}

  {% if userRoles contains "manager" %}
    <p>Welcome to the management section.</p>
  {% endif %}

{% endif %}

Debug tip  

Sometimes you will just want to see the web roles assigned to the user, to do this use the following code below.


<p>Roles for the user: {{ user.roles | join: ', ' }}</p>

Conclusion  

To recap use has_role to check individual roles and use contains to check for multiple web roles. Web roles are a great way to control what a user can view on a web page thanks to Liquid and at the same time adds an extra layer of security.

As always thanks for reading and take it easy!

How to learn Bootstrap for Power Pages 
On this page:
  • Example has_role
  • Example contains
  • Debug tip
  • Conclusion
Follow me on LinkedIn

 
Copyright © 2025 Calum Harrison. | Powered by Hinode.
Calum Harrison
Code copied to clipboard