Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Is it possible to substitute parameters in an user macro's body



I would like to know if there is a possibility to define an user macro containing parameters and a $body,  where the macro should replace the parameters in it, when the macro is being "previewed" or displayed?


##example user macro template

## @param user:title=User|type=string|desc=set username|required=true|multiple=false|default=

when using, the macro is included, parameter "user = m.mustermann" together with a body "Hello, $!user" is provided:


The goal is when the confluence page is saved or on preview to have this:

"Hello, max.mustermann"

I know that I can write following user macro:

##example user macro template

## @param user:title=User|type=string|desc=set username|required=true|multiple=false|default=

Hello, $!user

 and it works like a charm, but every time the body of the macro should be expanded with new information especially such using the parameter I should contact system administrator in order to get the new "version" of the macro which is kinda loosing the point of using such macro at the first place.

Thank you in advance

3 answers

1 vote

Yes you can do what you want, but differently that you describe, What you want to do is retrieve the current user. 

#set($currentUser= $action.authenticatedUser)

The you would basically find the methods for name (getUserFullName I think will work). Parse that string for the first name, and bingo, it will alway display who is viewing the page.


You can also access the user's group:

#set($groups = $userAccessor.getGroupNames($currentUser))

I have used this trick to hide buttons/functions from users not belong to the correct group.


If you want a nice display like Confluence, then:

<div class="content-wrapper"><p>
<ri:user ri:userkey="$currentUser.key"/>

thank you for taking time to reply to my question. What you describe is handy and I will remember it so it may be of use in the future.

@Petko Welcome the Atlassian Community

Parameter values are provided by the user when they add or edit the macro.  Objects are available to you for certain page, space or content including parameters.  The object is what is eventually displayed in the macro or used to define page behavior.  You cannot have a parameter that is an object but you can have an object that is a parameter.

I've followed the provided guide in order to create my macro. Thank you for taking time to consider and reply to my question.

I believe my example was misinterpreted. The setup with the user was merely a try to provide an example of what I was trying to achieve namely to write a macro, where I am able to freely parameterize part of the information when I'm setting up the macro. I was able to create a macro with the text needed and parameters and every time I'm including the macro I just set values for the needed parameters and they get used in the text. The problem with this method is that each time when the text and perhaps new parameter is introduced I have to get in touch with the Administrator in order to have the body of the macro updated.

Actually later I found exactly what I was looking for: the plugin "Include Content" by Keysight Technologies- (  Their " (include) shared block with replacement" macro is exactly what I was trying to achieve - to create a text block within a page and set parameters which should have their values set when I'm including the text block somewhere else in the documentation. And each time when I want to change the text or the parameters I just need to edit the source page.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

333 views 2 7
Read article

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