Changes for page Writing XWiki Rendering Macros in wiki pages
Last modified by Clément Desableau on 2023/06/01
Change comment:
Fix doc: context --> xcontext
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -67,7 +67,7 @@ 67 67 68 68 {image:macro4.png} 69 69 70 -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 *$context.macro.params.greetUser*. We plan to introduce some form of direct parameter binding in near future. 70 +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. 71 71 72 72 Finally, we can test our new version of hello macro with the following invocation: 73 73 ... ... @@ -89,7 +89,7 @@ 89 89 90 90 {code} 91 91 {{velocity output="no"}} 92 -#if("$context.action" != "edit") 92 +#if("$xcontext.action" != "edit") 93 93 #set($ok = $xwiki.jsx.use("My.Extension")) 94 94 #end 95 95 ## ... ... @@ -103,11 +103,11 @@ 103 103 104 104 Following are few useful hints if you plan to do advanced scripting inside your wiki macros: 105 105 106 -* Access parameters: Use the context object (Ex. $context.macro.params.param1) 106 +* Access parameters: Use the context object (Ex. $xcontext.macro.params.param1) 107 107 108 -* Access macro body (if your macro defines one): Use the context object (Ex. $context.macro.content) 108 +* Access macro body (if your macro defines one): Use the context object (Ex. $xcontext.macro.content) 109 109 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. $context.macro.context) 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 111 112 112 * 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 make 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 ... ... @@ -141,7 +141,7 @@ 141 141 142 142 {code} 143 143 {{velocity}} 144 -#set($greetUser=$context.macro.params.greetUser) 144 +#set($greetUser=$xcontext.macro.params.greetUser) 145 145 #if ("true" == $greetUser && "XWiki.XWikiGuest" != "$xcontext.user" ) 146 146 Hello $xwiki.user.email! 147 147 #else ... ... @@ -159,12 +159,12 @@ 159 159 160 160 The second invocation will not print "Hello World!" as we'd expect. But it will print the same result as the first invocation. The reasons are: 161 161 * Macro parameters are implemented as global parameters. So, they remains the same across multiple macro invocations. 162 -* If $context.macro.params.greetUser contains "null", it will not be assigned to $greetUser. This is different from C/C++ or Java. 162 +* If $xcontext.macro.params.greetUser contains "null", it will not be assigned to $greetUser. This is different from C/C++ or Java. 163 163 164 164 So in order to get around it, you can use: 165 165 166 166 {code} 167 -#set($greetUser="$!context.macro.params.greetUser") 167 +#set($greetUser="$!xcontext.macro.params.greetUser") 168 168 {code} 169 169 170 170