User macros are short pieces of code that perform an often-used function or add some custom formatting to a page. People can add the macro to a page by choosing it from the Macro Browser when editing a Confluence page. The macro is run when the page is loaded by the browser. You can write a user macro by adding code on a screen in the Confluence Administration Console.

You need to have System Administrator permissions in order to create user macros.

代わりにプラグインが必要ですか?

If you want to distribute your user macro as a plugin, please refer to the developer's guide to the User Macro plugin module. If you want to create more complex, programmatic macros in Confluence, you may need to write a Macro plugin.

 このページの内容

(warning) The information on this page does not apply to Confluence OnDemand.

Creating a User Macro

To create a user macro:

  1. Go to the Confluence Administration Console and click User Macros in the left-hand panel.
  2. Click Create a User Macro.
  3. Supply the information in the input fields as explained below, then click Add.

The sections below tell you about each of the input fields.

macroName

Enter the text that people will see when looking for the macro in the Macro Browser.

表示方法

Set the visibility options to specify who can see this macro when they are searching using the Macro Browser or Autocomplete.

User macros must have parameters defined in order to appear in the Confluence 4.0 Macro Browser.

The options are as follows:

Visibility Option

意味

すべてのユーザーに表示

All users will see this macro when searching for a macro using the Macro Browser or Autocomplete.

システム管理者にのみ表示

Choose this option if you want the macro to be 'hidden' from most users when the users are looking for a macro to add to a page. Note that this does not completely hide the macro. Instead, it is useful if you want to avoid cluttering the Macro Browser and Autocomplete with unnecessary macros. Specifically, if you are:

  • Editing a page and inserting a macro using the Macro Browser: Only system administrators will see this macro in the Macro Browser. For other users, the macro will not show up in the Macro Browser when the user searches for a macro to add to a page.
  • Editing a page and inserting a macro using Autocomplete: Only system administrators will see this macro in Autocomplete. For other users, the macro will not show up in the Autocomplete list when the user searches for a macro to add to a page.
  • Viewing the page: The macro output will be visible to all users who have permission to see the page.
  • Editing a page that already contains the macro: Provided a user has permission to edit the page, the macro will be visible to all users when editing the page, and all users who have permission to edit the page will also be able to edit or remove the macro.

Please note that all the macro information will also be discoverable, including the macro title, description, parameter names and other metadata. Do not include confidential data anywhere in the definition of a user macro, even if it is marked as visible only to system administrators.

マクロ タイトル

Enter the text that should appear in the Macro Browser and in Autocomplete, to identify this macro when people are looking for it to insert onto a page.

説明

Enter the text that should appear in the Macro Browser describing this macro. Note that the Macro Browser's search will pick up matches in the description as well as in the title.

カテゴリ

Select one or more categories for your macro. To select more than one category, hold down the 'Ctrl' key while selecting. These are the categories that appear in the Macro Browser, helping users to choose a macro from a logical set.

アイコンの URL

If you would like the Macro Browser to display an icon for your macro, enter the URL here. You can enter an absolute URL or a path relative to the Confluence base URL. For example:

  • Absolute URL:

    http://mysite.com/mypath/status.png
    
  • Relative URL:

    /images/icons/macrobrowser/status.png
    

ドキュメント URL

Enter the URL pointing to the online help or other documentation for your macro.

マクロ本文処理

Specify how you want Confluence to process the body of your macro before passing it to your macro. Below is an explanation of the macro body and the options available.

What is the macro body?

The macro body is the content that is displayed on the wiki page. If the macro allows a body, users will be able to enter body content when configuring the macro in the Macro Browser.

How can I use the macro body?

If you specify that your macro has a body, you will be able to pass text to the macro when you invoke it from within a page.

If your macro has a body, any body content that the user enters will be available to the macro in the $body variable. See the section about the template below. In addition, the options below allow you to tell Confluence to pre-process the body before it is placed in the macro output.

What are the options for macro body?

Body Processing Option

意味

No macro body

Select this option if your macro does not need a body.

エスケープ済み

If your macro has a body, and you make use of the body as $body in your template, Confluence will add escape characters to the HTML markup in the macro body. You could use this if you want to show the HTML markup in the rendered page. For example, if the body is:

<b>Hello World</b>

Then value of $body will be:

&lt;b&gt;Hello World&lt;/b&gt;

This will render as:

<b>Hello World</b>
UnrenderedIf your macro has a body, and you make use of the body as $body in your template, HTML in the body will be processed within the template before being output. Ensure that HTML is ultimately output by the template.

レンダリング済み

If your macro has a body, and you make use of the body as $body in your template, Confluence will recognise HTML in the macro body. For example, if the body is:

<b>Hello World</b>

Then value of $body will be:

<b>Hello World</b>

This will render as:
Hello World

 

テンプレート

Enter code to specify what the macro will do. For example, to add a macro inside the macro you are writing, you would write:

<ac:macro ac:name="someOtherMacro" />

クイック ガイド:

  • Use HTML and Confluence-specific XML elements in the macro template. Details of Confluence's storage format are in Confluence Storage Format.
  • You can use the Velocity templating language. Here is more information on the Velocity project.
  • マクロに本文がある場合、"$body" を指定することでテンプレートでマクロの本文のテキストを参照できます。
  • Each parameter variable you use must have a matching metadata definition. Use @param to define metadata for your macro parameters.
  • When using the information passed using parameters, refer to your parameters as $paramXXX where 'XXX' is the parameter name that you specifed in the @param metadata definition.
  • Use @noparams if your macro does not accept parameters.

See our detailed guide to writing a user macro template.

Examples and Best Practices

参照先:

関連トピック

Developer documentation:

Community contributions

Be careful when installing user macros. Ideally use only macros from authors and sources that are well known to you.

  • ラベルなし