User Macro embedded in footer source fails

The macro defined below works as intended in it's source page (such as footer) but when the footer is rendered in a page which includes the footer it fails. It appears the script cannot detect the context. Any ideas why this doesn't work.

Source Page:

Target Page

## Macro title: Space Administrators
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 28/04/2012
## Installed by: <your name>

## Macro to list all users and groups with the permission to administer the current space.
## @noparams

<h3>Space Adminstrators</h3>
<p>The following users and groups have permission to administer the <strong>$space.getName()</strong> Space.</p>

<h4>Users</h4>

<ul>
  #foreach ($permission in $space.getPermissions())
    #if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
       <li> #usernameLink($permission.getUserName())</li>
    #end
</ul>
  #end
</table>

<h4>Groups</h4>

#foreach ($permission in $space.getPermissions())
  #if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
    #set ( $groupString = $permission.getGroup() )
    #set ( $groupObject = $userAccessor.getGroup($groupString) )
    #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )

    <h5>$groupString</h5>
<ul>
      #foreach ($member in $memberList)      
          <li>#usernameLink($member)</li>
      #end
</ul>
  #end
#end

3 answers

1 accepted

Hmm... by default Theme Press renders the footer content in the context of the footer page (not in the context of the viewing page) so it shouldn't behave any differently, in theory. A couple of questions:

  1. Was the same user account used for both screenshots above?
  2. Are there any errors printed in the log files when viewing the target page?

Regardless, I'm assuming that the intent is to display that permissions info for the target page. This won't be the case in the default mode, since the permissions for the space the footer is in (themepressdefault:) will be shown on all pages. You can remedy this by going to the footer page, and opening the Theme Press Designer's "Footer" tab. In the "Handling" section, check "Render in Context" so the footer will render in the target page's context. (Note, this means that rendered footers are no longer cached, so adds a slight amount of extra work for page views.) Give this a shot to see if that remedies the error you're seeing above.

An alternative to checking the Render in Context box is to add the macro to the page layout. Layout contents are merged into the page before rendering, so will always be in the target page's context, plus skips a rendering step so slightly faster (of course the macro itself adds overhead).

Note the performance implications discussed above are typically in the 50-100 milliseconds range, so not user detectable. Only a consideration on systems that are already stressed...

That works! BTW I wrapped the user macro in the Bob Swift Cache macro to workaround the caching issue.

NASR 2087138

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

1,891 views 25 10
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you