Using Liquid and Web Roles together in Power Pages
Posted on May 24, 2025 (Last modified on May 25, 2025) • 2 min read • 284 wordsDo 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.
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 %}
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 %}
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>
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!