Changes for page Writing XWiki Rendering Macros in wiki pages
Last modified by Anca Luca on 2023/01/10
Change comment:
Add a sample of parsing macro content in velocity to avoid nested scripting error
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. VincentMassol1 +XWiki.dgervalle - Content
-
... ... @@ -144,7 +144,15 @@ 144 144 This text will not appear in the result. 145 145 {code} 146 146 147 +* 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: 147 147 149 +{code} 150 +{{velocity output="no"}} 151 +#set($wikiresult = $xcontext.macro.content) ## get the macro content in a velocity string 152 +#set($wikiresult = "(% class='newstyle' %)((($wikiresult)))") ## Add a wrapping div as a sample of what the macro could do 153 +#set($xcontext.macro.result = $services.rendering.parse($wikiresult, $xwiki.getCurrentContentSyntaxId()).getChildren()) ## parse the string and return the resulting blocks 154 +{{/velocity}} 155 +{code} 148 148 1.1 Troubleshooting 149 149 150 150 1.1.1 A Pitfall of Optional Parameters