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

Community site session details

Session Id : t1MlyrCmBpOWOWQahpfRxP
Power Pages - General Discussions
Answered

How to display user roles on site in Power Pages

Like (0) ShareShare
ReportReport
Posted on 31 Dec 2024 07:45:01 by 4
Hello Everyone,
In Visual Studio Code I would like to get and display the role of the currently logged in user, I log in using a local account. So far I have managed to write such code but it does not get any roles, it constantly displays that the user is not logged in:
 
<div>
  <h2>Roles of the currently logged in user:</h2>
  {% if currentUser %}
    <ul>
      {% assign userRoles = currentUser.roles | split: ',' %}
      {% for role in userRoles %}
        <li>{{ role }}</li>
      {% endfor %}
    </ul>
  {% else %}
    <p>No user data found. Check if you are logged in.</p>
  {% endif %}
</div>
Categories:
I have the same question (0)
  • Daniel MS Profile Picture
    4 on 31 Dec 2024 at 09:25:35
    How to display user roles on site in Power Pages
    Dziękuje Oliver, o to właśnie chodziło! Zrobiłem jeszcze drobną zmianę w kodzie i teraz wyświetla aktualne role użytkownika:
     
    <div>
      <h2>Roles of the currently logged in user:</h2>
      {% if user %}
        <ul>
          {% for role in user.roles %}
            <li>{{ role }}</li>
          {% endfor %}
        </ul>
      {% else %}
        <p>No user data found. Check if you are logged in.</p>
      {% endif %}
    </div>
  • Verified answer
    oliver.rodrigues Profile Picture
    9,347 Most Valuable Professional on 31 Dec 2024 at 09:12:19
    How to display user roles on site in Power Pages
    Hi, where are you assigning the value to currentUser variable?
     
    this should be just user, for example:
     
     
    <div>
      <h2>Roles of the currently logged in user:</h2>
      {% if user %}
        <ul>
          {% assign userRoles = user.roles | split: ',' %}
          {% for role in userRoles %}
            <li>{{ role }}</li>
          {% endfor %}
        </ul>
      {% else %}
        <p>No user data found. Check if you are logged in.</p>
      {% endif %}
    </div>
     

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…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Pages

#1
Jon Unzueta Profile Picture

Jon Unzueta 119 Super User 2025 Season 2

#2
KevinGador Profile Picture

KevinGador 34 Super User 2025 Season 2

#3
SwatiSTW Profile Picture

SwatiSTW 24 Super User 2025 Season 2

Last 30 days Overall leaderboard
Loading complete