Is it possible to substitute parameters in an user macro's body
Asked by Petko:

Hello,

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:

    ##example user macro template

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

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


Answers:
author: Bill Bailey
body: 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](https://docs.atlassian.com/ConfluenceServer/javadoc/7.16.0/com/atlassian/confluence/core/ConfluenceActionSupport.html#getUserFullName-java.lang.String-) I think will work). Parse that string for the first name, and bingo, it will alway display who is viewing the page.

**Bonus**

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>
<ac:link>
<ri:user ri:userkey="$currentUser.key"/>
</ac:link>
</p>
</div>
```

comments: author: Petko Ichev
body: 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.


author: Brant Schroeder
body: [@Petko](/t5/user/viewprofilepage/user-id/4607737) 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.

<https://confluence.atlassian.com/doc/user-macro-template-syntax-223906130.html#UserMacroTemplateSyntax-Definingtheparameters>

comments: author: Petko Ichev
body: I've followed the provided guide in order to create my macro. Thank you for taking time to consider and reply to my question.


author: Petko Ichev
body: 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](https://marketplace.atlassian.com/vendors/1211991/keysight-technologies)- ([https://marketplace.atlassian.com/apps/1217141/include-content?tab=overview\&hosting=server](https://marketplace.atlassian.com/apps/1217141/include-content?tab=overview&hosting=server)). 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.