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

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

This widget could not be displayed.

{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

This widget could not be displayed.

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

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

356 views 2 5
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