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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to secure (i.e hid...
Power Pages
Unanswered

How to secure (i.e hide/show) Page content for different web roles users in portal

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

 

I am trying to display different page content for the different login user. So, I have created two different web roles and assigned those web roles to a different set of contacts.

Now I want to display different content/views for different web roles users. I can give the page level security from portal management but need to secure the page contents based on login user web roles. (i.e in Home page different content/views will be visible to different  login user based on its web role)

 

Any help will be appreciable.

Thanks,

Amit

Categories:
I have the same question (0)
  • Christian Leverenz Profile Picture
    1,214 on at

    Hi @Anonymous ,

    not sure but if i have those kinds of requests i write liquid code to achieve this.

    So, i think this is not an out-of-the-box feature, you have to create something. 

    Presumably, this: https://docs.microsoft.com/en-us/powerapps/maker/portals/liquid/liquid-objects#user is what you want, especially the part {% if user.roles contains 'Administrators' %} User is an administrator. {% endif %} .

    in fact i had a request for example, to show a specific form based on a condition, so i had something like

    {% if iseditable %}
        {% entityform idpage.adx_entityform.id %}
    {% else %}
        {% entityform name"<rmyeadonly entity form> (overview)" %}
    {% endif %}
    ehere the variable iseditable was assigned a value based on the status of my entity. Could have been set by a role as well 🙂
     

    Hope it helps,

      Christian

     

  • H V Profile Picture
    1,510 on at

    Hi,
    As I understand, you want to hide/show content based on logged-in user(contact) role.

    Please add below code in page's javascript section. 

    $(document).ready(function(){
    
    var loggedInUserRole = '{{ user.roles }}'; 
    // you will get all the roles in above variable as string
    
    //check that user has role or not
    if (loggedInUserRole.indexOf("Administrator") >= 0) {
     $("#divId").show(); 
     // you can manage your content here
    } 
    else
    { 
     $("#divId").hide();
     // you can manage your content here
    }
    });

     

     

  • Christian Leverenz Profile Picture
    1,214 on at

    Hi together,

    @hardikv  code will definitely work. There are things to keep in mind:

    • using client side javascript to hide/show things will place the content of both roles on the page and it could be inspected by the frontenduser. If this is not an issue, this is ok
    • the usres could see the content before the script is run (depending on latency, bandwidth and clientperformance). A better approach is to hide the div by default and only to show when applicable
    • when you want to show a diffrent form or list or webform or other serverrelated stuff you can not do this kind of things on the client as it is to be serverrendered. If thgis is not a requirement, its ok to do things on the client

    Another question is, where the content comes from. Usually, the field adx_copy is rendered as the pagecontent. When you want to use the same webpage for two roles, you either have to invent a new field on adx_webpage (which might cause trouble when the system is updated) or you create snippets to hold the extracontent. I would definitely recommend the latter one.

    So i like @hardikv  approach but you have to keep in mind what will go to the browser and what should ber changed when a specific role sees the page.

     

    Keep on coding and have fun,

      Christian

  • MichaelFP Profile Picture
    1,847 Super User 2025 Season 2 on at

    Create a Liquid Template and validate the role. And after extending each one with the content

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard