Last modified by Simon Urli on 2023/10/10

From version 121.1
edited by Michael Hamann
on 2022/06/28
Change comment: There is no comment for this version
To version 120.1
edited by Thomas Mortagne
on 2022/01/04
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.MichaelHamann
1 +XWiki.ThomasMortagne
Content
... ... @@ -60,6 +60,11 @@
60 60  
61 61  Note that by default this makes the content of the macro directly editable in [[the WYSIWYG editor>>https://extensions.xwiki.org/xwiki/bin/view/Extension/CKEditor%20Integration/#HWikiMacros]].
62 62  )))
63 +* Another way to manipulate the content is to use the wikimacro binding. For example, when using Velocity, you can write the following script in the macro body:(((
64 +{{code language='none'}}
65 +{{velocity}}$wikimacro.content{{/velocity}}
66 +{{/code}}
67 +)))
63 63  {{/version}}
64 64  
65 65  For more details, see the [[Scripting Tips section below>>||anchor="HScriptingTips"]].
... ... @@ -84,7 +84,7 @@
84 84  {{code language="none"}}
85 85  {{velocity}}
86 86  #if ($wikimacro.parameters.greetUser && "XWiki.XWikiGuest" != "$xcontext.user")
87 - Hello $services.rendering.escape($xwiki.user.email, 'xwiki/2.1')!
92 + Hello $xwiki.user.email!
88 88  #else
89 89   Hello world!
90 90  #end
... ... @@ -94,7 +94,7 @@
94 94  As you might have realized already, direct binding of parameters is not supported at the moment. That is, you cannot access //greetUser// parameter with **$greetUser**. Instead you must use **$wikimacro.parameters.greetUser**. We plan to introduce some form of direct parameter binding in near future.
95 95  
96 96  Since {{info}}11.5RC1{{/info}}, it is also possible to display the content of a macro parameter by using a dedicated macro:
97 -{{code language="none"}}Hello {{wikimacroparameter name="greetUsers" /}}{{/code}}
102 +{{code language="none"}}Hello {{wikimacroparameter name="greeUsers" /}}{{/code}}
98 98  
99 99  Finally, we can test our new version of **hello macro** with the following invocation:
100 100  
... ... @@ -213,7 +213,7 @@
213 213  This text will not appear in the result.
214 214  {{/code}}
215 215  )))
216 -* If you need to directly access the parsed XDOM of the content you may do the parsing yourself using the rendering service. Here is a small sample:(((
221 +* If you are using ##$wikimacro.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:(((
217 217  {{code language="velocity"}}
218 218  {{velocity output="no"}}
219 219  ## get the macro content in a velocity string
... ... @@ -240,10 +240,11 @@
240 240  {{velocity}}
241 241  #set($greetUser=$xcontext.macro.params.greetUser)
242 242  #if ("true" == $greetUser && "XWiki.XWikiGuest" != "$xcontext.user" )
243 - Hello $services.rendering.escape($xwiki.user.email, 'xwiki/2.1')!
248 + Hello $xwiki.user.email!
244 244  #else
245 245   Hello world!
246 246  #end
252 +<img src="$image" width="$width" />
247 247  {{/code}}
248 248  
249 249  If we invoke it twice in a row:

Get Connected