Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Set $body of a user macro from inside the macro

Thorsten Reinhardt April 2, 2020

Hello everybody,

I'm looking for a way to set the value of a user macro's $body from inside the macro.

There is the following background for this. When creating a new Confluence page using a template, the user macro gets an initial value in the $body. This value is used as long as no other value is selected in the macro. (A value would be selected by editing the user macro and selecting a value there using the dropdown).

Here is the crucial question - if I choose a value other than the initial value in the macro, the value selected in the macro should be automatically set in the macro's $body to avoid irritation.

Within the macro, the value of the variable $body can be reset with

#set ($body = $paramXYZ)

but the value is then not adopted when saving.

Is there a solution for this?

1 answer

0 votes
Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 7, 2020

Hi @Thorsten Reinhardt 

I'm not an absolut expert with user macros, but I wrote a few easy ones. 

Let me guess, the value isn't adopting when saving the macro, but is adopting when saving the page? 

User Macros are rendered in the view mode of the page. As far as I know, you can't change the body text in the edit by changing the parameter. 

Look at my example, do I understand you correct? 

My Macro:

## This is an example macro
## @param Name:title=Name|type=string|required=false|desc=Your name


#set ($body = $paramName)
$body

Page in the edit mode

image.png

As you can see, the param is "Test BBBBB" and the body text is "Test AAAAA". The page in the view mode shows "Test BBBBB". Because when loading the page in view mode, the macro will be rendered and in the macro I defined: body=paramName.

Do you really need a body in the macro? Or could you do the same with only parameters and get rid of the body? 

Regards, Dominic

Thorsten Reinhardt April 16, 2020

Hi @Dominic Lagger, thank you for your response!

We chose the way through the body of the macro to be able to read an initial value from the dropdown that is set by a template (we use the Blueprint Creator from the Atlassian Marketplace).
If there was a more elegant solution to being able to set the value we get from the Blueprint Creator Template initially in the macro, you wouldn't need the body.

Unfortunately, we have not yet come up with such an elegant solution.

Regards, Thorsten

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events