How to add a custom code block macro?

How do I create a custom code block macro? I would like to have macros for languages we use with a standardized look.

 

This is what I have created in Configuration -> User Macros:

## @param codetitle:title=Code title|type=string|required=true|desc=Title of the code macro
##
## Macro title: Python Single Code Line
## Macro has a body: Y
## Body processing: unrendered
## Output: Selected output option
##
## Developed by: me
## Date created: 07/10/2016
## Installed by: me
<ac:structured-macro ac:name="code">
  <ac:parameter ac:name="title">$codetitle</ac:parameter>
  <ac:parameter ac:name="theme">Default</ac:parameter>
  <ac:parameter ac:name="language">py</ac:parameter>
  <ac:plain-text-body><![CDATA[insert your code here]]></ac:plain-text-body>
</ac:structured-macro>

 

Unfortunately, this does not work: the title is not replaced by the value of $codetitle, thus just the string "$codetitle" appears in the title bar no matter what value the string $codetitle has.

Additionally, any modifications to the body are ignored. You can insert what you want into the body, the macro always displays "insert your code here".

How do I have to alter this macro in order to get it working properly?

1 answer

1 accepted

To the first question:

I guess you need to write $paramcodetitle. That is the proper way to use the macro parameters.

If this doesn't work name the parameter Codetitle (with a capital):

## @param Codetitle:title=Code title

and then use the parameter like this: $paramCodetitle

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

388 views 21 10
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