A Confluence macro that returns XHTML in the Confluence storage format. Note, unlike most Connect modules, this content is not displayed in an iframe. Instead, your macro is responsible for returning valid Storage Format XML to the confluence page, which Confluence will render for you at view time.
Please consult Confluence Storage Format for additional information about how to construct valid storage format XML.
Because any calls to the macro rendering service happen synchronously during page load, we strongly encourage the implementations to take advantage of HTTP's caching mechanisms: Often, the rendered content only depends on the macro's body and parameters. A good approach for this specific case is to prevent Connect from retrieving the content again, unless the parameters or body have actually changed:
1 2 3
res.set('Cache-Control', public, max-age=3600);
This response header tells the cache to use the response for an hour without asking the service again.
Because we declare the macro hash and parameters as URL variables, the URL will automatically change when the macro is changed.
This change will cause Connect to bypass the cache and to fetch the content from the add-on again.
So doing non-conditional caching works very well for this case. If the content of the macro varies with other data,
you could use ETag
and If-None-Match
to render the macro conditionally.
Also keep in mind that the calls are made from the Confluence server to the add-on host. If you need to prevent any caching on the server, use
1 2 3
Cache-Control: no-cache
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
{
"modules": {
"staticContentMacros": [
{
"renderingMethod": "get",
"url": "/render-map?pageTitle={page.title}",
"description": {
"value": "Shows a configurable map"
},
"icon": {
"width": 80,
"height": 80,
"url": "/maps/icon.png"
},
"documentation": {
"url": "http://docs.example.com/addons/maps"
},
"categories": [
"visuals"
],
"outputType": "block",
"bodyType": "none",
"aliases": [
"map"
],
"featured": true,
"parameters": [
{
"identifier": "view",
"name": {
"value": "Map View"
},
"description": {
"value": "Allows switching between view types"
},
"type": "enum",
"required": true,
"multiple": false,
"defaultValue": "Map",
"values": [
"Map",
"Satellite"
],
"hidden": false,
"indexing": {
"enabled": true
}
}
],
"autoconvert": {
"urlParameter": "url",
"matchers": [
{
"pattern": "https://www.example.com/maps/{}/{}"
},
{
"pattern": "https://www.example.com/map-editor/{}"
}
]
},
"editor": {
"url": "/map-editor",
"editTitle": {
"value": "Edit Map"
},
"insertTitle": {
"value": "Insert Map"
}
},
"name": {
"value": "Maps"
},
"key": "static-macro-example"
}
]
}
}
key
Type | |
Max length | 100 |
Required | Yes |
Pattern | ^[a-zA-Z0-9-]+$ |
Description | A key to identify the macro. Keys must only contain alphanumeric characters and dashes, and must be globally unique. Prefixing it with the name of your add-on is the best way to ensure this. |
name
Type | |
Required | Yes |
Description | A human readable name. Represents a string that can be resolved via a localization properties file. You can use the same Example1 2 3 4
|
value |
| ||||||||
i18n |
|
url
Type | |
Format | uri-template |
Required | Yes |
Description | The link to the add-on resource that provides the macro content. This URL has to be relative to the add-on base URL. Additional context parameters can be passed as variables in the URL: 1 2 3 4 5
Since macro bodies can be of arbitrary size and may contain sensitive data, care must be taken as to how its passed to your connect add-on. You have three options to gain access to the body:
- If you can predict the size of your body and it is consistently less than 128 characters, you
can include it in the GET request using the
Note: If you include the Here's an example: Declare the variables that are later required to fetch the macro content in the URL: 1 2 3 4 5
Then use the Confluence REST API to collect the body, for example directly from the iframe: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Preview Mode: If you use the
Note: Currently supported variables for macros are:
- Context parameters for macros are also required in the URL. Please see the Macro Input Parameter documentation for details. |
aliases
Type | |
Description | Define aliases for the macro. The macro browser will open for the defined aliases as if it were this macro. |
autoconvert
Type | |
Description | URL patterns associated with this macro. If a URL matching a defined pattern is pasted into the editor, this macro will be created and will replace the URL string. Autoconvert allows your macro to be inserted into the editor when a recognised URL is pasted in by the user. You define recognised URL patterns using 'matchers' which are registered in the editor when your add-on is installed. When the macro is created in the editor, the URL string that triggered the autoconvert will be captured and inserted as a parameter on the macro body. You must define the name of this parameter by providing a string value for 'urlParameter'. This allows you to access the URL that triggered the autoconvert. Example This example inserts a macro into the editor when a user pastes in certain simple Facebook links. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
urlParameter |
| ||||||||
matchers |
|
bodyType
Type | |||||||||||
Defaults to | none | ||||||||||
Allowed values |
| ||||||||||
Description | The type of body content, if any, for this macro.
|
categories
Type | |
Description | The categories the macro should appear in. A macro with no category will show up in the default 'All' category. Currently, the following categories are supported by Confluence:
|
description
Type | |
Description | A description of the macro's functionality. Represents a string that can be resolved via a localization properties file. You can use the same Example1 2 3 4
|
value |
| ||||||||
i18n |
|
documentation
Type | |
Description | A link to the documentation for the macro. Represents a link, its optional title and alternative text. Example1 2 3 4 5 6 7 8
|
url |
| ||||||||
altText |
| ||||||||
title |
|
editor
Type | |
Description | The configuration of a custom macro editor. This is useful if the parameter input field types are not sufficient to configure the macro. Macro Parameters go a long way when it comes to macro configuration, but there are cases when a macro add-on needs more control over the UI. Defining a Macro Editor allows you to implement a custom UI for the macro, by specifying a URL to a page in your add-on which will be shown in the dialog iFrame. In order to persist custom data in your macro editor, use the Javascript Confluence API and the Dialog API. For example:
AP.require(["confluence", "dialog"], function (confluence, dialog) { function onSubmit() { var macroParams = { myParameter: value }; confluence.saveMacro(macroParams); confluence.closeMacroEditor(); return true; } dialog.getButton("submit").bind(onSubmit); });
In order to retrieve the custom data again when the editor is opened, use AP.require("confluence", function (confluence) { var macroData = confluence.getMacroData(function(macroParams) { doSomethingWith(macroParams.myParameter); }); }); Example 1 2 3 4 5 6 7 8 9 10 11 12
|
url |
| ||||||||
cacheable |
| ||||||||
editTitle |
| ||||||||
height |
| ||||||||
insertTitle |
| ||||||||
width |
|
featured
Type | |
Defaults to | false |
Description | Whether the macro should be "featured", meaning having an additional link in the "Insert More Content" menu in the editor toolbar. |
hidden
Type | |
Defaults to | false |
Description | If set to true, the macro will not appear in the macro browser. |
icon
Type | |
Description | A link to the icon resource (80x80 pixels) that will be shown in the macro selection dialog. The URL can be absolute or relative to the add-on base URL. Defines an icon to display. Example1 2 3 4 5 6 7 8
|
url |
| ||||||||
height |
| ||||||||
width |
|
imagePlaceholder
Type | |
Description | The image rendered in the editor as the macro placeholder. It can only be used with bodyless macros and will behave just like a regular macro placeholder. Any parameter changes in the macro browser will cause the image to be reloaded - so that changes can be seen. Defines a macro image placeholder to display in the Confluence editor. Example 1 2 3 4 5 6 7 8 9
|
url |
| ||||||||
applyChrome |
| ||||||||
height |
| ||||||||
width |
|
outputType
Type | |
Defaults to | block |
Allowed values |
|
Description | How this macro should be placed along side other page content. |
parameters
Type | |
Description | The list of parameter input fields that will be displayed. |
propertyPanel
Type | |
Description | The configuration of a property panel. Specify a hidden iframe to be loaded in the macro's property panel. Defining a Macro Property panel allows you to add a hidden iframe to your macro's property panel. The iframe is loaded as soon as the property panel is opened. In order to persist custom data using your property panel, use the Javascript Confluence API. For example: AP.require(["confluence"], function (confluence) { var macroParams = { myParameter: value }; confluence.saveMacro(macroParams); });
In order to retrieve the custom data again when the property panel is opened, use AP.require("confluence", function (confluence) { var macroData = confluence.getMacroData(function(macroParams) { doSomethingWith(macroParams.myParameter); }); });
Dialogs may also be created. Use AP.require('dialog', function(dialog) { dialog.create({ key: 'my-module-key', width: '500px', height: '200px', chrome: true }).on("close", callbackFunc); }); |
url |
| ||||||||
cacheable |
| ||||||||
controls |
|
renderingMethod
Type | |
Defaults to | get |
Allowed values |
|
Description | HTTP method that will be used in the HTTP request.
For example: 1 2 3 4 5 6
Then Confluence will send a POST request to 1 2 3 4 5 6 7 8 9 10
Note: All the parameters will be sent via POST payload in
|
Rate this page: