It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Hide element based on group membership and pageid.

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

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

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
Community showcase
Posted in Confluence

What project did you transition or start on Confluence with the shift to remote work?

It’s been great to hear from fellow users over the last few weeks about the best tips and fun moments you’ve had working on Confluence since the transition to working remote. I’d love to keep the c...

397 views 11 11
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you