Show last authors
author | version | line-number | content |
---|---|---|---|
1 | #startfloatingbox() | ||
2 | *Contents* | ||
3 | #toc ("2" "3" "") | ||
4 | #endfloatingbox() | ||
5 | |||
6 | 1 Wiki Macro Tutorial | ||
7 | |||
8 | 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! | ||
9 | |||
10 | 1.1 Prerequisites | ||
11 | |||
12 | * Wiki macros are only available on XWiki Enterprise 2.0M2 and later versions | ||
13 | * Wiki macro authors need to have programming rights | ||
14 | * Wiki macros can only be defined inside the main wiki, though they can be used throughout a farm | ||
15 | |||
16 | 1.1 Hello Macro | ||
17 | |||
18 | 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. | ||
19 | |||
20 | 1.1.1 Hello Macro Definition | ||
21 | |||
22 | 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: | ||
23 | |||
24 | * Macro name: Name of the macro, which will be used by users to invoke your macro | ||
25 | |||
26 | * Macro description: A short description of the macro, this description will be made available on the WYSIWYG editor (More on this later) | ||
27 | |||
28 | * Macro content type: Whether this macro should support a body or not | ||
29 | |||
30 | * Content description: A short description about the macro's content, this description will also be available on the WYSIWYG editor | ||
31 | |||
32 | * Macro code: The actual wiki code that will be evaluated when the macro is executed, can be any xwiki content (should be in the same syntax as the document) | ||
33 | |||
34 | Now we can define our hello macro as shown below: | ||
35 | |||
36 | {image:macro1.png} | ||
37 | |||
38 | 1.1.1 Hello Macro Invocation | ||
39 | |||
40 | A wiki macro can be invoked just like any other macro is invoked. Since we are writing a xwiki/2.0 wiki macro, we can invoke our hello macro as below: | ||
41 | |||
42 | {code} | ||
43 | {{hello/}} | ||
44 | {code} | ||
45 | |||
46 | And if you view the result it would say "Hello World!" (of course). | ||
47 | |||
48 | 1.1 WYSIWYG Access | ||
49 | |||
50 | A wiki macros is treated just like any other rendering macro in the system. As such, the moment you save your wiki macro it will be available to the users through the WYSIWYG editor's *Insert Macro* dialog box: | ||
51 | |||
52 | {image:macro2.png} | ||
53 | |||
54 | #error("This document is being updated") |