Hide element based on group membership and pageid.

Henrik Juel Petersen November 7, 2019

Hi,

I am trying to find a way to add an if statement to the "main layout" of a space, under site layouts, that checks if a user is a part of a group 'xxx' and if the current pageid == 'yyy'
I am able to do this through a user macro, that I can add to a page - I would just prefer not having to add that user macro to EVERY page I'd like this functionality on.


The problem is, when I add the pageid part of the usermacro to the "mainlayout" then it dont do anything.


Anyone has an idea of how to solve this?

Thanks!


Look and feel - Layout - Main layout:

This if statement is working:
#if(${action.authenticatedUser} && ${userAccessor.hasMembership('xxx', ${action.authenticatedUser.name})})
<script type="text/javascript">
AJS.toInit(function(){
AJS.$('#quick-create-page-button').remove();
AJS.$('#create-page-button').remove();
});
</script>
#else
#end

 


User macro that works as intended:
## @@noparam
#if(${action.authenticatedUser} && ${userAccessor.hasMembership('xxx', ${action.authenticatedUser.name})} && $content.getId() == 'yyy' || $content.getId() == 'yyyy')
<script type="text/javascript">
AJS.toInit(function(){
AJS.$('#quick-create-page-button').remove();
AJS.$('#create-page-button').remove();
});
</script>
#else
#end

1 answer

1 accepted

0 votes
Answer accepted
Aleksandr Zuevich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2019

Hi @Henrik Juel Petersen ,

I suppose this is because decorator macro doesn't include $content object. 

But I think you can use something like the next script:

#if(${action.authenticatedUser} && ${userAccessor.hasMembership('xxx', ${action.authenticatedUser.name})})
<script type="text/javascript">
AJS.toInit(function(){
if (AJS.Meta.get('page-id') == 'yyy' || AJS.Meta.get('page-id') == 'yyyy') {
AJS.$('#quick-create-page-button').remove();
AJS.$('#create-page-button').remove();
}
});
</script>
#else
#end
Henrik Juel Petersen November 8, 2019

Hi @Aleksandr Zuevich 

I solved this, by keeping it in the macro, but adding the macro in the "page layout" under content layouts.

Added this line within the "page-metadata-banner" tag:

$helper.renderConfluenceMacro("{hidecreatebtnontitleandgroup}")

Up till now i haven't found a scenario, where it dosnt fix what I wanted it too.

 

Thanks for the input :)

/Henrik

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events