Reuse Existing Macros
Some existing macros have many complex parameters, and you may want to get some standardization over their usage. Script macros provide an easy way to standardize parameters.
For example, the Table of Contents macro has many parameters. Use the following task as an example of re-using existing macro parameters:
In a sample page, configure the Table of Contents macro parameters like you would want your users to.
View the storage format of the page.
To view the storage format, you need the Confluence Source Editor plugin.
Copy the macro XHTML from the storage format, which should look similar to the following image:
Create a new script macro with no body and no parameters.
Add script to the macro, which should look similar to the following code:
import com.atlassian.confluence.xhtml.api.XhtmlContent import com.atlassian.sal.api.component.ComponentLocator def xhtmlContent = ComponentLocator.getComponent(XhtmlContent) xhtmlContent.convertStorageToView(""" <ac:structured-macro ac:name="toc" ac:schema-version="1"> <ac:parameter ac:name="maxLevel">3</ac:parameter> <ac:parameter ac:name="indent">12px</ac:parameter> <ac:parameter ac:name="class">my-class</ac:parameter> <ac:parameter ac:name="printable">false</ac:parameter> </ac:structured-macro> """, context)
You must use the
convertStorageToView
method, as shown in the example code, to convert from storage format to HTML.
When you finish this task, the new macro uses the Table of Contents macro parameters.
For an example, view the Include All Child Pages example.