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

This widget could not be displayed.

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.

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

87 views 13 7
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