The Macro Browser helps users to browse and insert macros while adding or editing content. If you are a plugin author, this page provides details on how to make use of the new Macro Browser framework.
Starting from Confluence 4.0, all macros must contain metadata to function correctly in Confluence.
To make sure your macro appears and behaves correctly in the Macro Browser, and displays the correct parameter input fields, you need to make simple additions to your macro definition in the atlassian-plugin.xml
file.
The following macro attributes contain information specifically for the Macro Browser.
Name | Description |
---|---|
documentation-url | The absolute URL pointing to the macro documentation. |
icon | The relative URL to the application for the macro icon. To display well in the macro browser, the image should be 80 pixels by 80 pixels, with no transparency. |
hide-body | This attribute is available for macros that falsely declare that they have body (most likely because they extend `BaseMacro`) when they don't. Default: false. |
hidden | If set to true, the macro is not visible in the Macro Browser for selection. Plugin authors may want to hide macros that are for their plugin's internal use and shouldn't really be used by users. Default: false. |
The following macro elements contain information specifically for the Macro Browser.
They should be placed inside your <xhtml-macro>
element.
Name* | Description |
---|---|
category | The category the macro should appear in. Valid categories are listed below. |
alias | Defines an alias for the macro. This means that the Macro Browser will open for the defined aliases as if it were this macro. |
parameters | Defines a group of parameter elements. See example below. |
parameter | This defines a single macro parameter. It must be an element of the parameters element. Its contents are described below. |
*parameters is a required element.
The following categories for macros are defined (see MacroCategory). A macro with no category will show up in the default 'All' category.
formatting
confluence-content
media
visuals
navigation
external-content
communication
reporting
admin
development
Each <parameter>
element must have the following attributes:
name
— A unique name of the parameter, or "" for the default (unnamed) parameter.type
— The type of parameter (see MacroParameterType).
Currently the following parameter types are supported in the Macro Browser UI:
boolean
— displays a check box.enum
— displays as a drop-down.string
— displays an input field (this is the default if type is unknown).spacekey
— displays an autocomplete field for search on space names.attachment
— displays an autocomplete field for search on attachment filenames.username
— displays an autocomplete field for search on username and full name.confluence-content
— displays an autocomplete field for search on page and blog titles.The following parameter attributes are optional:
required
— use to mark parameter as required, defaults to 'false'.multiple
— use to mark that parameter may have several values, defaults to 'false'.default
— use to define the default value for the parameter.It can also have the following optional child elements:
<alias name="xxx"/>
— alias for the macro parameter.<value name="xxx"/>
— describes a single 'enum' value - only applicable for enum typed parameters.To send information along with your form, you can define a hidden parameter, which will be invisible for users. Take a look at the following examples on how to define this.
In the atlassian-plugin.xml
, define a string
parameter:
1 2<xhtml-macro name="example-formatting" key="example-formatting" class="some.path.ExampleFormatting.java" icon="/download/resources/${atlassian.plugin.key}/images/example-formatting.png"> <category name="formatting"/> <parameters> <parameter name="willbehidden" type="string"/> </parameters> </xhtml-macro> <resource type="download" name="images/" location="images"> <param name="content-type" value="image/png"/> </resource> <web-resource key="hidden-field-parameter" name="Add a hidden field"> <resource type="download" name="hidden-parameter-field.js" location="js/hidden-parameter-field.js" /> <dependency>confluence.editor.actions:editor-macro-browser</dependency> <context>macro-browser</context> </web-resource>
Inside the js/hidden-parameter-field.js
, add the following:
1 2AJS.MacroBrowser.setMacroJsOverride("example-formatting", { fields: { string: { "willbehidden": function (param) { var parameterField = AJS.MacroBrowser.ParameterFields["_hidden"](param, {}); if (!parameterField.getValue()) { parameterField.setValue('hidden field value'); } return parameterField; } } } });
Autocompletion on the parameter types may show up that hidden
is also a supported type. Keep in mind that choosing this type will not make the field hidden.
The following code is an example of parameter use:
1 2<xhtml-macro name="example-parameters" documentation-url="http://docs.example.com/some/path" class="some.path.ExampleFormatting.java" key="example-parameters"> <category name="confluence-content"/> <parameters> <parameter name="users" type="username" multiple="true"/> <parameter name="spaces" type="spacekey" multiple="true"> <alias name="space"/> </parameter> <parameter name="labels" type="string"> <alias name="label"/> </parameter> <parameter name="width" type="percentage" default="100%"/> <parameter name="types" type="string"> <alias name="type"/> </parameter> <parameter name="max" type="int" default="15"> <alias name="maxResults"/> </parameter> <parameter name="theme" type="enum"> <value name="concise"/> <value name="social"/> <value name="sidebar"/> </parameter> <parameter name="showProfilePic" type="boolean"/> <parameter name="hideHeading" type="boolean"/> </parameters> </xhtml-macro>
Note that the previous example contains parameter types that aren't all supported in the macro browser UI, but may be in future releases.
To provide an icon for your macro, perform the following steps:
Create a resource for icons/images
if you don't already have one. e.g.
1 2<resource key="icons" name="icons/" type="download" location="myplugin/images/icons"/>
This must be a top-level resource in your atlassian-plugin.xml
and must be defined before the macro.
Ensure your plugin contains the resource directory myplugin/images/icons
.
Set the icon attribute on the macro. For example:
1 2icon="/download/resources/pluginkey/icons/iconfile.png"
Instead of having to define i18n keys for each element in the macro definition, the following convention is used to look up i18n keys for the macro browser.
Key | Description |
---|---|
{pluginKey}.{macroName}.label | Macro label/display name |
{pluginKey}.{macroName}.desc | Macro description |
{pluginKey}.{macroName}.param.{paramName}.label | Macro parameter label |
{pluginKey}.{macroName}.param.{paramName}.desc | Macro parameter description |
{pluginKey}.{macroName}.body.label | Macro body label (defaults to 'Body Text' if not provided) |
{pluginKey}.{macroName}.body.desc | Macro body description |
You will need to place the keys in a .properties file with a resource of type i18n in your plugin.
Rate this page: