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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to display user ro...
Power Pages
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:
  • Verified answer
    oliver.rodrigues Profile Picture
    9,482 Most Valuable Professional on at
    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>
     
  • Daniel MS Profile Picture
    4 on at
    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>

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Pages

#1
M Bilal Khan Profile Picture

M Bilal Khan 110

#2
sannavajjala87 Profile Picture

sannavajjala87 30 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 24

Last 30 days Overall leaderboard