2

I am trying to make some page corrections only for some groups of site ins Sharepoint. I can check admin user in master page with SPSecurityTrimmedControl, but how can I insert custom css into master page only for let's say Read Only users? If I am trying like this:

<SharePoint:SPSecurityTrimmedControl PermissionsString="ViewPages" runat="server"> 

Css adds up not only for Read Only users but for Admin user as well. Is there any chances to split .css by groups? Thank you

2
  • Do you want to hide a (custom) ribbon button from certain users? If so, I would not use CSS. You can add JavaScript 'validation scripts' to a ribbon button to determine if it is enabled or disabled for a certain user/group.
    – Wout
    Feb 9, 2016 at 8:47
  • how can I make this? Feb 9, 2016 at 10:12

3 Answers 3

1

Right now I am doing like this:

    <SharePoint:SPSecurityTrimmedControl PermissionsString="ViewPages" runat="server"> 
       <link rel="stylesheet" type="text/css" href="https://sharepoint.com/web/SiteAssets/css-readonly.css" />
</SharePoint:SPSecurityTrimmedControl>

<SharePoint:SPSecurityTrimmedControl PermissionsString="ManageWeb" runat="server"> 
        <link rel="stylesheet" type="text/css" href="https://sharepoint.com/web/SiteAssets/custom-css.css" />
</SharePoint:SPSecurityTrimmedControl>

add it always uses those two .css on admin site. So the question is how to split it from Admin and Read Only user?

1

The best way to do this is keep the trim controls but instead of adding the css directly create to empty divs with 2 different ids. Then using a script in the master inject the css based on the div that exist in the page for each individual user. Note that the admin will have both divs on the page.

Here you have a sample code using jQuery

   <SharePoint:SPSecurityTrimmedControl PermissionsString="ViewPages" runat="server"> 
   <div id="readonly></div>
</SharePoint:SPSecurityTrimmedControl>

<SharePoint:SPSecurityTrimmedControl PermissionsString="ManageWeb" runat="server"> 
    <div id="admin></div>
</SharePoint:SPSecurityTrimmedControl>

<script type="text/javascript">
    if($('#readonly').length != 0 && $('#admin').length == 0)
    {
        $('head').append('<link rel="stylesheet" type="text/css" href="https://sharepoint.com/web/SiteAssets/css-readonly.css" />');
    }
    else if($('#readonly').length != 0 && $('#admin').length != 0 )
    {
        $('head').append('<link rel="stylesheet" type="text/css" href="https://sharepoint.com/web/SiteAssets/custom-css.css" />');
    }
</script>
0
<SharePoint:SPSecurityTrimmedControl Permissions="whatever" runat="server">
<style type="text/css">
    #some-element { display: block; }
</style> </SharePoint:SPSecurityTrimmedControl>

Is that what you're asking?

2
  • I did something like that, the idea is admin always has All permissions, so it pass SPSecurityTrimmedControl always and adds up .css to admin page. Feb 8, 2016 at 23:18
  • Couldn't you just change the admin CSS to work even when the readonly CSS has already been applied? Seems like you can solve it with just CSS to me. Feb 8, 2016 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.