Skip to main content

Notifications

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
    Daniel MS 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
    oliver.rodrigues 8,962 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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #9 Get Recognized…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,215

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,290

Leaderboard

Featured topics