|
We provide these user macros as simple examples just to get you started. You would not want to install these user macros onto your Confluence site.
Take a look at an example of a 'Hello World' macro.
Let's write a simple macro that creates a red box (using an existing Confluence style) around some text. This may be useful for writing about error conditions, for example. That is why we give this macro the name 'error'.
To create the 'Error' user macro:
errorVisible to all users in the Macro BrowserErrorDisplays a red box around some textConfluence ContentRendered
Template:
<div class="error">$body</div> |
To use the macro within a page, use the Macro Browser. Your page will display an error box, like this:
This is bad |
This example demonstrates how you can pass parameters into your macro. Let's say you want to write your own font colour macro:
<span style="color: $param0">$body</span> |
The usage of this macro will be:
{colour:green}Some example text{colour}
|
The output will be:
Some example text
If your macro requires more than one parameter, you can use variables $param0 to $param9 to represent them. To specify multiple parameters, use:
{colour:red|blue|green}
|
Where red, blue and green are the 1st, 2nd and 3rd parameters respectively.
Alternatively, you can also use explicitly named parameters in your macro. These macro parameters will appear as variables with the name $param<x> where <x> is the name of your parameter. To specify named parameters, use:
{style:colour=red}
|
In your user macro you can then use $paramcolour which will have the value red in this case.
You may want to take a look at the library of user-contributed user macros.
Be careful when installing user macros from unknown authors.