How to use Jira-Keys in Confluence (User) Macros

This example uses a new template in Confluence and will utilize the following Add-ons.

Step-by-step guide


1. Create an new template in Confluence

  1. Insert the macro you want to use e.g. Insight Objects
  2. Configure the macro to your likings
  3. Save the templatee
  4. Open the template again in edit mode, to enable the source editor
  5. Open the source editor with the <> icon in the upper right corner
  6. Select the macro source starting with <ac:structured-macro and ending with </ac:structured-macro>

In the source of the macro change the "macro-id" (increment on number) to avoid conflicts with the original macro.

Due to the id it's also only possible to add one macro to the template.

If you need a user-macro multiple times you have to configure it multiple times.

2. Open in a second browser tab User Macros under Confluence administration

  1. Create a new user macro
  2. Configure the macro to your likings
  3. Set under the Definition of User Macro the option to Rendered
  4. Exchange the source with the one from the Macro Base further down this page
  5. Replace the ## Exchange me from the Macro Base with the source from Step 1.6
  6. Likely you'll have a line like <ac:parameter ac:name="iql">key in (XYZ-1)</ac:parameter>
    • Replace the IQL e.g. key in (XYZ-1) with $body
  7. Save your macro

3. Back to the template

  1. Close the editor and reload the page
  2. If present remove the original insight macro
  3. Add the new user macro to the page
  4. Add in the macro your IQL while replacing the value with an confluence variable 

Macro Base
## Macro title: Dynamic Insight Objects
## Macro has a body: Y
## Body processing: Rendered
## Output: Insight Object Data
## Developed by: ---
## Date created: 2019-02-22
## Installed by: --- ---
## @noparams
#set ($body = $body.replaceAll("\Q&lt;p&gt;\E",""))
#set ($body = $body.replaceAll("\Q&lt;/p&gt;\E",""))
#set ($body = $body.trim())

## Exchange me

Take care to hit cancel in the source editor.

Save will break the confluence variables which wont work anymore with Issue to Page