Confluence 3.5 のサポートは終了しています。
ドキュメントの最新バージョンを確認してください。
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:
Examples of Working User Macros
These user macros are examples that you may want to install onto your Confluence site.
Working Example 1: The Expand Macro
See Writing the Expand User Macro.
Working Example 2: The Status Macro
See Writing the Status User Macro.
Simple and Illustrative Examples of User Macros
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.
Simple Example 1: User Macro to Display 'Hello World'
Take a look at an example of a 'Hello World' macro.
Simple Example 2: The 'Error' User Macro to Create a Red Box
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,
- Go to the Confluence Administration Console and click 'User Macros' in the left-hand panel.
- Click the link on the text 'Click here to create a new User Macro' at the top of the list of macros.
- Enter the macro attributes as follows:
- Macro Name:
error
- Visibility:
Visible to all users in the Macro Browser
- Macro Title:
Error
- Description:
Displays a red box around some text
- Categories:
Confluence Content
- Icon URL: You can leave this field empty.
- Documentation URL: You can leave this field empty.
- Macro Body Processing:
Render HTML
- Output Format:
HTML
- Template:
<div class="error">$body</div>
- Macro Name:
- [保存] をクリックします。
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
Simple Example 3: User Macro to Demonstrate the Use of Parameters
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.
User-Contributed User Macros
You may want to take a look at the library of user-contributed user macros.
Be careful when installing user macros from unknown authors.