2

I know that you can target audiences on web parts and such, but can you hide/show a page title depending on a site's permission group?

enter image description here

1 Answer 1

3

As far as I'm aware, you can't hide the title OOTB. You'd have to add some sort of third party tool, or run some javascript.

You could look into adding a script editor webpart in with code similar to the following:

<script language="javascript">
$( function() {
    // Get context for current page, set a permission level to evaluate, and set query to 
    // check if they have these base permissions
    var ctx = new SP.ClientContext.get_current();
    var web = ctx.get_web();
    var ob = new SP.BasePermissions();
    ob.set( SP.PermissionKind.manageWeb )
    var per = web.doesUserHavePermissions( ob )

    // Execute Query
    ctx.executeQueryAsync(
        function() { // On Success Query
           var titleField = document.getElementById( "DeltaPlaceHolderPageTitleInTitleArea" )
            if ( per.get_value() ) {
               titleField.style.display = "inherit"
            } else {
               titleField.style.display = "none"
            }
        },
        function( a, b ) { // On Failed query
        } );
} );
</script>

It's a self-executing function that checks for the user's current base permission level (like Edit, Contribute, Full Control, etc) then inside the success function (commented with // On Success Query) you put your script to change display. This exact setup works on my publishing page on-prem 2013. To change the permission type, you'll have to select a new Enumeration. You can use this reference to get the different enumeration types. To select your enumeration type, change SP.PermissionKind.manageWeb to SP.PermissionKind.anotherEnumerationwhere anotherEnumeration is from the reference above.

3
  • Thanks so much for the guidance! This is definitely more guidance than I was expecting so I do appreciate it. Originally, I was planning to go down the JavaScript route, but I was unsure how to target a custom groups permissions so I really do appreciate the guidance!
    – SLE
    Commented Dec 13, 2018 at 21:38
  • @SaintLouisEvents No problem! Good luck. But please note that this doesn't do custom permissions. Just base permissions. I don't know the best way to get "if User is in (HomePage - Members) group" but it'll still allow you to say "If User has (Contribute) permissions to site" .
    – KGlasier
    Commented Dec 13, 2018 at 21:46
  • I might be able to set some custom permissions for that particular group and just target that, so it still helps as some guidance. I tried checking dev console to see if there is a div class/etc.. added between hidden content on audience targeting but nothing was showing.
    – SLE
    Commented Dec 13, 2018 at 21:55

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.