ContentsThe [toc] macro is a standalone macro and it cannot be used inline. Click on this message for details.

Wiki Macro Tutorial

Wiki macros allow macro authors to develop reusable and distributable macro modules. There is no java code involved; hence no compiling or packaging. Macro author simply needs to create a wiki page according to a particular specification and that's all!

Prerequisites

  • Wiki macros are only available on XWiki Enterprise 2.0M2 and later versions
  • Wiki macro authors need to have programming rights
  • Wiki macros can only be defined inside the main wiki, though they can be used throughout a farm

Hello World Macro

We are going to start with a very simple xwiki/2.0 wiki macro which prints a greeting message to the document content. It isn't a very useful macro but the idea is to get you familiarised with the wiki macro creation process.

XWiki.WikiMacroClass

Wiki macros are defined using objects of type XWiki.WikiMacroClass. You define a wiki macro by creating a new wiki page and attaching it an object of type XWiki.WikiMacroClass. This class contains following fields:

  • Macro name: Name of the macro, which will be used by users to invoke your macro
  • Macro description: A short description of the macro, this description will be made available on the WYSIWYG editor (More on this later)
  • Macro content: The actual wiki content that will be evaluated when the macro is executed, can be any wiki content (should be in the same syntax as the document)

Now we can define our hello world wiki macro as shown below:

macro1.png

Invoking Hello World Macro

A wiki macro can be invoked just as any other macro is invoked. Since we are writing a xwiki/2.0 wiki macro, we can invoke our hello world macro as below:

{{hello/}}
Tags:
   

Get Connected