Confluence: How to escape double quotes in user macros?


I'm writing a lot of user macros and stumble upon this one problem every now and then:

I have no idea how to escape double quotes properly. In this specific case I'm writing a macro that holds Bob Swifts run&cli plugins, where quotes are needed. Here's a code example:

#set($globalHelper = $action.getHelper())

#set ($update = $globalHelper.renderConfluenceMacro("{run:replace=status:green:Lorem ipsum?:radio::green::yellow::red|titleRun=lorem!}
--action storePage --space xxx --title "yyy" --content "zzz"
Status aktualisiert.

The part within the {cli-stuff makes the problems.

I tried single quotes, escaping with backslash...even HTML entities, nothing is working properly. With quotes like above I get an error message when using the macro (of course), when escaping the values are set exactly with the chars I used to escape.

I'm really hoping there's a solution for this :)

2 answers

1 accepted

Hello Superuschi,

I stumbled into the same problem today and found that:

Thus, I solved my problem by introducing a constant containing the quote character

#set( $q = '"' )

and using it like that:

#set( $style = "style=${q}$paramStyle${q}" )

Hope that helps.


Your solution also worked for me. I needed to expand a file name using a user supplied variable but the period and suffix were causing problems. Ther period needed to be separated from the variable name by whitespace or the variable would not be replaced witht the user supplied value :-(

I used this technique to create a suffix variable that was set to ".rss" and then my macro worked like a charm.


Nice to hear that, Matthew.

Okay, I figured that in this case, I can just use no quotes at all in the cli-part. Won't work in other cases though.

Suggest an answer

Log in or Join to answer
Community showcase
Maarten Cautreels
Posted Thursday in Off-topic

Friday Fun: What's your favourite beer/drink

As a Belgian, beer-lover and home brewer, beer is one of my great passions. I love the fact that with just a few ingredients (usually just water, hop and malt) you can create so many different tastes...

285 views 38 9
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot