Confluence 2.6 : User Macros
This page last changed on Apr 18, 2007 by david.soul@atlassian.com.
User macros are simple template-like macros that allow you to create simple formatting macros using the Confluence web interface.
To create a user macro,
Options for 'Macro has a body':When you select 'Macro has a body', anything the user types within the body of the macro will be available in the macro in the $body variable. The options below allow you to tell Confluence to pre-process the body before it is placed in the macro output.
Writing user macros: some examples
As an example, let's write a simple macro that simply creates a red box (using an existing Confluence style) around some text (useful for writing about error conditions for example - hence the macro name 'error'). After clicking "New User Macro", enter error as the Name of your macro, and then put the following in the Template text area:
<div class="errorbox">$body</div>
Then click Add. You should now see your new macro in the User Macros library, and you can now enable and disable it individually. To use the macro within a page, you would add notation like: {error}This is bad{error} And your page would (magically!) have an error box on it, like so: This is bad Another example to demonstrate how you can pass parameters into your macro. Say you wanted to write your own font colour macro: <span style="color: $param0">$body</span>
The usage of this macro would be: {colour:red}Some example text{colour} which will produce: 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. Available objectsThe user macro above uses the $body object, which is available for use within your user macro template if the macro has a body. You can pass parameters to your user macro in the same way as any other macro (separated by | signs), these parameters are provided to your template as param1, param2. . . paramN.
The complete list of objects available for use are:
More information on object usage is available from the Velocity Template Overview. User Macro LibraryBelow is a list of existing user macros that can be installed.
|
![]() |
Document generated by Confluence on Oct 10, 2007 18:49 |