Last modified by Simon Urli on 2023/10/10

<
From version < 85.3 >
edited by Denis Gervalle
on 2013/02/23
To version < 86.1 >
edited by Valdis Vitolins
on 2013/09/10
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.dgervalle
1 +XWiki.valdisvi
Content
... ... @@ -47,10 +47,17 @@
47 47  
48 48  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:
49 49  
50 -{{code}}{{hello/}}{{/code}}
50 +{{code}}
51 +{{hello/}}
52 +{{/code}}
51 51  
52 52  And if you view the result it would say "Hello World!" (of course).
53 53  
56 +== Content ==
57 +
58 +If macro content is used, it can be shown by executing following velocity code in macro body:
59 +{{code language="none"}}{{velocity}}$xcontext.macro.content{{/velocity}}{{/code}}
60 +
54 54  == Parameters ==
55 55  
56 56  Introducing a parameter to a wiki macro is pretty straight forward; you simply need to add an object of type ##XWiki.WikiMacroParameterClass## into your wiki macro document (one object per parameter). This class contains several fields that allow you to define your parameter clearly:
... ... @@ -71,7 +71,9 @@
71 71  
72 72  Finally, we can test our new version of **hello macro** with the following invocation:
73 73  
74 -{{code language="none"}}{{hello greetUser="true"/}}{{/code}}
81 +{{code language="none"}}
82 +{{hello greetUser="true"/}}
83 +{{/code}}
75 75  
76 76  = WYSIWYG Access =
77 77  
... ... @@ -108,8 +108,7 @@
108 108  * Access parameters: Use the context object (Ex. ##$xcontext.macro.params.param1##)
109 109  * Access macro body (if your macro defines one): Use the context object (Ex. ##$xcontext.macro.content##)
110 110  * Access [[MacroTransformationContext>>http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/transformation/MacroTransformationContext.java]]: Use the context object (Ex. ##$xcontext.macro.context##)
111 -* Since 2.4M1, it's possible to directly return the desired list of rendering blocks without having to render them first to let them be parsed back by the macro transformation. The benefits are that it could be a lots quicker and most of all it means supporting syntax which does not provide any renderer. It also makes it possible to generate some XDOM which is impossible to write in any some syntax. For example the following wiki macro is generating a LinkBlock targeting a relative URL:
112 -(((
120 +* Since 2.4M1, it's possible to directly return the desired list of rendering blocks without having to render them first to let them be parsed back by the macro transformation. The benefits are that it could be a lots quicker and most of all it means supporting syntax which does not provide any renderer. It also makes it possible to generate some XDOM which is impossible to write in any some syntax. For example the following wiki macro is generating a LinkBlock targeting a relative URL:(((
113 113  {{code language="groovy"}}
114 114  {{groovy}}
115 115  import java.util.Collections;
... ... @@ -129,8 +129,7 @@
129 129  This text will not appear in the result.
130 130  {{/code}}
131 131  )))
132 -* If you are using ##$xcontext.macro.content## in your velocity macro, that content will not be able to support scripting, since nested scripting is not supported. To workaround that limitation, thanks to the above, you may do the parsing yourself using the rendering service. Here is a small sample:
133 -(((
140 +* If you are using ##$xcontext.macro.content## in your velocity macro, that content will not be able to support scripting, since nested scripting is not supported. To workaround that limitation, thanks to the above, you may do the parsing yourself using the rendering service. Here is a small sample:(((
134 134  {{code languege="velocity"}}
135 135  {{velocity output="no"}}
136 136  ## get the macro content in a velocity string
... ... @@ -142,6 +142,7 @@
142 142  {{/velocity}}
143 143  {{/code}}
144 144  )))
152 +
145 145  = Troubleshooting =
146 146  
147 147  == A Pitfall of Optional Parameters ==

Get Connected