Confluence 4.0 : Examples of User Macros
This page last changed on Aug 31, 2011 by pwatson.
Below are some sample user macros. To see how to write a user macro and add it to your Confluence site, take a look at our guide to writing user macros. On this page: Simple Examples of User MacrosWe 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. Example 1: User Macro to Display 'Hello World'Take a look at an example of a 'Hello World' macro. Example 2: The 'Error' User Macro to Create a Red BoxLet'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:
To use the macro within a page, add wiki markup like this: {error}This is bad{error} Your page will display an error box, like this: This is bad Example 3: User Macro to Demonstrate the Use of ParametersThis 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: 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}
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 User-Contributed User MacrosYou may want to take a look at the library of user-contributed user macros. |
![]() |
Document generated by Confluence on Sep 19, 2011 02:42 |