It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set $body of a user macro from inside the macro

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 Community Leader Apr 07, 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

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
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

8,411 views 6 6
Join discussion

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