How can I use a user macro in a {code} block?

Simon Hardy-Francis August 23, 2011

I have a user macro called {username} which works great in an {info} block but gets displayed verbatim as '{username}' in a {code:language=bash} block. How can get the {code:language=bash} to respect the macro?

2 answers

2 votes
David Peterson
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.
August 23, 2011

{code} and {noformat} are special-case macros in Confluence - they both ignore any wiki markup therin. You could get around it in two ways:

1. Use a different type of block (eg. {quote}).

2. Inject the value you want to put in using {replace-and-render} or Reporting. Eg:

{replace-and-render}
  {replace-item:%username%}{username}{replace-item}
  {replace-body}{code:language=bash}Blah blah %username% blah blah{code}{report-body}
{replace-and-render}

Hope that helps!

Regards,

David Peterson

0 votes
David Peterson
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.
August 23, 2011

P.S. You'll need the 'Replace and Render' plugin for that example to work. :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events