Last modified by Simon Urli on 2023/10/10

<
From version < 110.1 >
edited by Simon Urli
on 2019/07/03
To version < 111.1 >
edited by Simon Urli
on 2019/07/03
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -73,9 +73,9 @@
73 73  
74 74  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]].
75 75  )))
76 -* The older way to insert the content is to use the ##xcontext## binding. For example, when using Velocity, you can write the following script in the macro body:(((
76 +* 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:(((
77 77  {{code language="none"}}
78 -{{velocity}}$xcontext.macro.content{{/velocity}}
78 +{{velocity}}$wikimacro.content{{/velocity}}
79 79  {{/code}}
80 80  )))
81 81  
... ... @@ -99,7 +99,7 @@
99 99  
100 100  [[image:macro4.png]]
101 101  
102 -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 **$xcontext.macro.params.greetUser**. We plan to introduce some form of direct parameter binding in near future.
102 +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.
103 103  
104 104  Since {{info}}11.5RC1{{/info}}, it is also possible to display the content of a macro parameter by using a dedicated macro:
105 105  {{code language="none"}}Hello {{wikimacroparameter name="greeUsers" /}}{{/code}}
... ... @@ -146,7 +146,7 @@
146 146  
147 147  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:
148 148  
149 -[[image:macro2.png]]
149 +[[image:macro2.png]]
150 150  
151 151  [[image:macro5.png]]
152 152  
... ... @@ -174,9 +174,10 @@
174 174  
175 175  Following are a few useful hints if you plan to do advanced scripting inside your wiki macros:
176 176  
177 -* Access parameters: Use the context object (Ex. ##$xcontext.macro.params.param1##)
178 -* Access macro body (if your macro defines one): Use the context object (Ex. ##$xcontext.macro.content##)
179 -* Access [[MacroTransformationContext>>https://github.com/xwiki/xwiki-rendering/blob/master/xwiki-rendering-transformations/xwiki-rendering-transformation-macro/src/main/java/org/xwiki/rendering/transformation/MacroTransformationContext.java]]: Use the context object (Ex. ##$xcontext.macro.context##)
177 +* Old and new bindings: please note that the ##$wikimacro## binding is only available since {{info}}XWiki 10.11.9, 11.3.2 and 11.6RC1{{/info}}, before that the ##$xcontext.macro## binding should be used. You can get more information on [[the reference documentation page>>doc:extensions:Extension.WikiMacroStore.WebHome||anchor="HBindings"]]
178 +* Access parameters: Use the wikimacro object (Ex. ##$wikimacro.params.param1##)
179 +* Access macro body (if your macro defines one): Use the wikimacro object (Ex. ##$wikimacro.content##)
180 +* Access [[MacroTransformationContext>>https://github.com/xwiki/xwiki-rendering/blob/master/xwiki-rendering-transformations/xwiki-rendering-transformation-macro/src/main/java/org/xwiki/rendering/transformation/MacroTransformationContext.java]]: Use the wikimacro object (Ex. ##$wikimacro.context##)
180 180  * 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:(((
181 181  {{code language="groovy"}}
182 182  {{groovy}}
... ... @@ -191,21 +191,21 @@
191 191  
192 192  ref linkBlock = new LinkBlock(Collections.singletonList(new WordBlock("Edit home page"))), link, false);
193 193  
194 -xcontext.macro.result = Collections.singletonList(linkBlock)
195 +wikimacro.result = Collections.singletonList(linkBlock)
195 195  {{/groovy}}
196 196  
197 197  This text will not appear in the result.
198 198  {{/code}}
199 199  )))
200 -* 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:(((
201 +* 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:(((
201 201  {{code languege="velocity"}}
202 202  {{velocity output="no"}}
203 203  ## get the macro content in a velocity string
204 -#set($wikiresult = $xcontext.macro.content)
205 +#set($wikiresult = $wikimacro.content)
205 205  ## Add a wrapping div as a sample of the action of this macro
206 206  #set($wikiresult = "(% class='newstyle' %)((($wikiresult)))")
207 207  ## parse the string and return the resulting blocks
208 -#set($xcontext.macro.result = $services.rendering.parse($wikiresult, $xwiki.getCurrentContentSyntaxId()).getChildren())
209 +#set($wikimacro.result = $services.rendering.parse($wikiresult, $xwiki.getCurrentContentSyntaxId()).getChildren())
209 209  {{/velocity}}
210 210  {{/code}}
211 211  )))

Get Connected