Think of macros as mini-applications or content snippets that you can embed within your Confluence pages. Theyāre like magical little boxes that can do anything from displaying dynamic content to creating interactive elements on your page.
How do Macros Work?
At their core, macros are XML elements in the Confluence Storage Format. When a page is rendered, Confluence processes these XML elements and replaces them with the appropriate output.
Hereās a simple example of what a macro looks like in the storage format:
<ac:structured-macro ac:name="info">
<ac:rich-text-body>
<p>This is an important note!</p>
</ac:rich-text-body>
</ac:structured-macro>
When rendered, this might appear as a blue info box on your Confluence page.
Types of Macros
- Built-in Macros: These come pre-installed with Confluence. Examples include: Table of Contents Info, Note, Warning boxes Code Block Expand/Collapse sections
- User Macros: These are custom macros created by users or admins using the Confluence macro browser.
- Plugin Macros: These are provided by Atlassian or third-party plugins, extending Confluenceās functionality.
Common Use Cases for Macros
- Dynamic Content: The JIRA Issues macro can display a live, updating list of issues from JIRA. The Chart macro can create graphs from data in Confluence tables.
- Page Structure: The Table of Contents macro automatically generates a clickable index of your page headings. The Column macro allows you to create multi-column layouts.
- Interactive Elements: The Expand macro creates collapsible sections of content. The Include Page macro lets you embed content from other pages.
- Rich Media: The Gallery macro creates image galleries. The Widget macro allows embedding of external web content.
- Development and Documentation: The Code Block macro displays formatted code snippets. The Excerpt and Excerpt Include macros allow for content reuse across pages.
Creating and Using Macros
- While editing a page, click the ā+ā button or type ā/ā to open the macro browser.
- Search for the desired macro and select it.
- Configure the macro parameters in the dialog that appears.
- The macro placeholder will be inserted into your page.
Advanced Macro Usage
- Nesting Macros: You can put macros inside other macros for complex layouts and functionality.
- Macro Parameters: Many macros accept parameters to customize their behavior. For example:
<ac:structured-macro ac:name="code">
<ac:parameter ac:name="language">java</ac:parameter>
<ac:plain-text-body><![CDATA[System.out.println("Hello, World!");]]></ac:plain-text-body>
</ac:structured-macro>
- User Macros: Admins can create custom macros using Velocity templating language, which can include HTML, CSS, and JavaScript.
Macros and Performance
While macros are powerful, they can impact page load times, especially if:
- They pull data from external systems (like JIRA)
- There are many macros on a single page
- They perform complex calculations
Confluence often employs caching strategies to mitigate these performance impacts.
Macros in the Bigger Picture
Macros are a key part of what makes Confluence more than just a wiki. They transform it into a dynamic platform for collaboration and information sharing. By leveraging macros, teams can create rich, interactive documents that serve as living resources for their projects and knowledge bases.
Now, let me provide some additional context and examples to help you understand macros even better:
- Real-world Example: Imagine youāre managing a software project in Confluence. You could use macros to: Display a live status board of current sprint tasks (JIRA Issues macro) Show a burn-down chart of project progress (Chart macro) Include a collapsible section of technical documentation (Expand macro) Embed the latest build status from your CI/CD pipeline (HTML macro)
- Macro Development: For developers, creating custom macros is a way to extend Confluenceās functionality. Hereās a simple example of a user macro that displays a customized greeting:
## Macro title: Greeting
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Your Name
## Date created: dd/mm/yyyy
## Installed by: Your Name
#set($name = $paramName)
#if(!$name)
#set($name = "World")
#end
<div class="greeting">
<h2>Hello, $name!</h2>
<p>Welcome to our Confluence space.</p>
</div>
This macro could be used like this: {greeting:name=Alice}
- Macro Security: Itās worth noting that macros can have security implications. For example, the HTML macro allows embedding of arbitrary HTML, which could potentially be used maliciously. Confluence admins often restrict the use of certain macros to trusted users.
- Macros and Confluenceās Evolution: Over the years, Atlassian has introduced more sophisticated macro capabilities. For instance, the Page Properties and Page Properties Report macros allow for structured data management across pages, almost like a lightweight database within Confluence.
- Macros in Templates: Confluence templates often make heavy use of macros to create standardized page layouts and functionality. This is particularly useful for things like meeting notes, project plans, or technical specifications.
- Macros and Adaptability: One of the strengths of the macro system is its adaptability. As Confluence evolves, new macros can be added to support new features without fundamentally changing the underlying storage format.
Understanding macros is key to mastering Confluence. Theyāre what allow you to transform Confluence from a simple document repository into a dynamic, interactive knowledge base tailored to your organizationās needs.
Remember, with great power comes great responsibility. While itās tempting to use macros for everything, sometimes simple text and formatting can be more effective. Use macros judiciously to enhance your content, not overwhelm it.š”