Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - General Discussions
Answered

How to display user roles on site in Power Pages

(0) ShareShare
ReportReport
Posted on 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:
  • Daniel MS Profile Picture
    4 on at
    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,342 Most Valuable Professional on at
    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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 1

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 1

#3
surya narayanan Profile Picture

surya narayanan 35