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

Accepted Answer
3 votes

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 Sign up to answer
Community showcase
Posted yesterday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

42 views 2 4
View post

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