Space admin tag macro- how to edit?
Asked by Sarah Dyer:

I'm trying to do something very simple- allow users to see the administrator of the space they are in.  
There's an out of the box macro called Soace Admin Tag- which gives minimal options, just asks you for the space key, and then displays in text the name of the users who are space admin of that space.  
As our intranet has nearly 200 spaces, I want to use this macro in the site footer, which for the foreseeable is the primary footer across every space.  
My issue is that I need to have the macro pull the space key from the space the footer is displayed in- rather than me have to set this on a space only footer, and set for EVERY space.  
Any ideas how to bespoke the macro to pull 'this space key' rather than a specified space key on setup?


Answers:
author: Fabio Racobaldo _Herzum_
body: Hi Sarah,

you can define the following macro :

```
## Macro title: My Macro
## Macro has a body: Y or N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Fabio Racobaldo
## Date created: 28/03/2018
## Installed by: Fabio Racobaldo
## @noparams

#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($users = $userAccessor.getUsers())
#set($spaces = $spaceManager.getAllSpaces())

<table class="confluenceTable">
<tr>
<th class="confluenceTh">Space Administrator</th><th class="confluenceTh">Space</th>
</tr>
#foreach($user in $users)
#if ($permissionHelper.canAdminister($user, $space))
<tr>
<td class="confluenceTd">#usernameLink($user.name)</td><td class="confluenceTd"><a href="$req.contextPath/display/$spacer.key">$space.name</a></td>
</tr>
#end
#end
</table>
```

Hope this helps.

Ciao,

Fabio

comments: author: Sarah Dyer
body: Hey Fabio,

Thanks for much for coming back to me, very much appreciated!

I'm not the most advanced user of Confluence - I've created this user macro with your details above, but it seems to pull through a list of every space and every space admin.

I've got a very basic Space Admin Tag macro that it might be worth just editing (as per below)- I've attached what this looks like front end, and essentially does everything I need it to - just need to have it display the space admin of the space the user is in, not a predefined space key. Does that make sense?

-------

## @param SpaceKey:title=The Space Key\|type=string\|required=true\|desc=Use the space key to determine who the Space Admins are

#set($thisSpace = "")

#if($paramSpaceKey)  
#set($thisSpace = $spaceManager.getSpace($paramSpaceKey) )  
#else  
##set($thisSpace = $space )  
#end  
#if ($thisSpace)

\<!-- $paramSpaceKey --\>

#set($spaceadmins = $spaceManager.getSpaceAdmins($thisSpace))

#set ($counter = 0)  
#if ($spaceadmins.size() \> 0)  
\<span\>Space Admin:\</span\>  
#foreach($spaceadmin in $spaceadmins)  
#if ($counter \< 2)  
#if ($counter \> 0)\<span\>,\</span\>#end  
\<span class="spaceadmin-user"\>\<a href="mailto:$spaceadmin.getEmail()"\>$spaceadmin.getFullName()\</a\>\</span\>  
#set ($counter = $counter + 1)  
#end  
#end  
#end  
#end

---------

![space admin macro.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/18172iAC565127AE413640/image-size/large?v=v2&px=999 "space admin macro.PNG")


author: Fabio Racobaldo _Herzum_
body: Hi Sarah,

the provided code should retrieve information just about the space related to the page in with the macro is used. I just tested it to my environment and it works.

Are you sure that you are using the correct one?