Wiki source code of Rendering Macros
Last modified by Eleni Cojocariu on 2026/11/26 11:19
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | A [[rendering macro>>doc:extensions:Extension.RenderingMacroTransformation.WebHome]] is called so because XWiki works it out [[while rendering the Page>>doc:documentation.xs.user.rendering.WebHome]], and it is what the editors and the rest of this documentation call simply a Macro. | ||
| 2 | |||
| 3 | == A Macro in the Editor == | ||
| 4 | |||
| 5 | You insert a Macro from the editor, and [[Ways to Insert a Macro>>doc:documentation.xs.user.rendering.macros.ways-insert.WebHome]] describes the route each one offers. Once inserted, the Macro is a single block you can select, move or delete: | ||
| 6 | |||
| 7 | {{image reference="macro-editor.png" size="large" alt="The Table of Contents macro selected in the WYSIWYG editor, outlined as a single block."/}} | ||
| 8 | |||
| 9 | The list inside that block cannot be typed into, because XWiki builds it only when the Page is displayed. | ||
| 10 | |||
| 11 | == Name, Parameters and Content == | ||
| 12 | |||
| 13 | Every Macro has a **name**, which is what identifies it. Most Macros also take **parameters**, the settings the editor asks you for: how deep the table of contents goes, the title of a box. Some take **content** as well, the text they act on, and that content can itself hold other Macros. | ||
| 14 | |||
| 15 | Those three things are what the [[Wiki editor>>doc:documentation.xs.user.content-edit.edit-wiki-editor.WebHome]] shows you directly, since there you write the Macro yourself: | ||
| 16 | |||
| 17 | {{code language="none"}} | ||
| 18 | {{box title="Release"}} | ||
| 19 | Freeze the branch. | ||
| 20 | {{/box}} | ||
| 21 | {{/code}} | ||
| 22 | |||
| 23 | A Macro that takes no content closes itself instead, like the ##toc## Macro that builds a table of contents. | ||
| 24 | |||
| 25 | == A Macro on the Displayed Page == | ||
| 26 | |||
| 27 | Opening the Page displays what each Macro produced: | ||
| 28 | |||
| 29 | {{image reference="macro-output.png" size="large" alt="The list of links the table of contents macro produced, above the first heading it points at."/}} | ||
| 30 | |||
| 31 | Add a heading to that Page later and the list gains an entry on its own, with nothing for you to update. | ||
| 32 | |||
| 33 | == Where Macros Come From == | ||
| 34 | |||
| 35 | * Bundled with XWiki, which is the set a new wiki already has. | ||
| 36 | * Added by an [[extension>>doc:documentation.xs.user.extensions.WebHome]] an administrator installed, and taken away again when that extension is uninstalled. | ||
| 37 | * Written on the wiki itself, since an advanced user can [[define a Macro in a wiki Page>>doc:documentation.xs.dev.rendering-macros.wiki-macros.WebHome]] without writing any Java. | ||
| 38 | |||
| 39 | == When a Macro Cannot Run == | ||
| 40 | |||
| 41 | Because a Macro runs while the Page is being displayed, it can fail at that moment. XWiki then replaces that one Macro by an error box and displays the rest of the Page normally: | ||
| 42 | |||
| 43 | {{image reference="macro-error.png" size="large" alt="An error box replacing a macro that is not installed, between the two paragraphs of the page."/}} | ||
| 44 | |||
| 45 | Clicking the box tells you what went wrong, and names the extension that provides the Macro when XWiki recognises it. The usual causes are a Macro that is not installed on this wiki, a misspelled Macro name, and a parameter value the Macro does not accept. |