<
From version < 117.1 >
edited by Vincent Massol
on 2021/01/05
To version < 117.2 >
edited by Vincent Massol
on 2021/01/05
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -41,7 +41,7 @@
41 41  * **Default category**: Default category under which this macro should be listed
42 42  * **Supports inline mode**: Whether the macro can be used in an inline context or not
43 43  * **Macro Content availability**: {{warning}}before 11.5RC1 this was called **Macro Content Type**{{/warning}} whether this macro should support a body or not
44 -* **Macro content type**: {{warning}}this field has been renamed **Macro Content Availability** since 11.5RC1{{/warning}} the type of accepted content: two values are proposed, ##WIKI## if this content should be editable like a wiki content, or ##UNKNOWN## if it should be displayed like a plain text. It's also possible to specify a custom java type such as {{code}}java.util.List<java.lang.String>{{/code}}. Leaving the field blank is equivalent to ##UNKWOWN## value.
44 +* **Macro content type**: {{warning}}this field has been renamed **Macro Content Availability** since 11.5RC1{{/warning}} the type of accepted content: two values are proposed, ##WIKI## if this content should be editable like a wiki content, or ##UNKNOWN## if it should be displayed like a plain text. It's also possible to specify a custom java type such as {{code language='java'}}java.util.List<java.lang.String>{{/code}}. Leaving the field blank is equivalent to ##UNKWOWN## value.
45 45  * **Content description**: A short description about the macro's content to be displayed on the WYSIWYG editor
46 46  * **Macro code**: The actual wiki code that will be evaluated when the macro is executed, can be any xwiki content (should be in the same syntax as the document)
47 47  * **Asynchronous rendering**: {{info}}Since 10.10{{/info}} Enabled or disable asynchronous rendering of the panel. Disabled by default.
... ... @@ -56,7 +56,7 @@
56 56  
57 57  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:
58 58  
59 -{{code}}
59 +{{code language='none'}}
60 60  {{hello/}}
61 61  {{/code}}
62 62  
... ... @@ -67,7 +67,7 @@
67 67  Starting with {{code}}XWiki 11.4RC1{{/code}} there are two ways to insert the content of the wiki macro.
68 68  
69 69  * The easiest way is to use a dedicated macro in the body of the wikimacro:(((
70 -{{code language="none"}}
70 +{{code language='none'}}
71 71  {{wikimacrocontent/}}
72 72  {{/code}}
73 73  
... ... @@ -74,7 +74,7 @@
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 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 -{{code language="none"}}
77 +{{code language='none'}}
78 78  {{velocity}}$wikimacro.content{{/velocity}}
79 79  {{/code}}
80 80  )))
... ... @@ -98,7 +98,7 @@
98 98  
99 99  A macro parameter defined this way can be accessed from any scripting language within the macro code. For example, we are going to utilize our //greetUser// parameter within **hello macro** as shown below:
100 100  
101 -{{code}}
101 +{{code language='none'}}
102 102  {{velocity}}
103 103  #if ($wikimacro.parameters.greetUser && "XWiki.XWikiGuest" != "$xcontext.user")
104 104   Hello $xwiki.user.email!
... ... @@ -111,17 +111,17 @@
111 111  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.
112 112  
113 113  Since {{info}}11.5RC1{{/info}}, it is also possible to display the content of a macro parameter by using a dedicated macro:
114 -{{code language="none"}}Hello {{wikimacroparameter name="greeUsers" /}}{{/code}}
114 +{{code language='none'}}Hello {{wikimacroparameter name="greeUsers" /}}{{/code}}
115 115  
116 116  Finally, we can test our new version of **hello macro** with the following invocation:
117 117  
118 -{{code language="none"}}
118 +{{code language='none'}}
119 119  {{hello greetUser="true"/}}
120 120  {{/code}}
121 121  
122 122  If you want to call the new version of the **hello macro** with a parameter from a variable you will need to wrap the call in a velocity macro like this:
123 123  
124 -{{code language="none"}}
124 +{{code language='none'}}
125 125  {{velocity}}
126 126  #set ($greet = true)
127 127  {{hello greetUser="$greet"/}}
... ... @@ -132,7 +132,7 @@
132 132  
133 133  When your macro is ready, you might want to provide the description of the macro and its parameters in different languages. For that, you need to create a set of translation keys and values (as described [[here>>platform:DevGuide.InternationalizingApplications]]) and then just use the following convention for the keys you add in this storage (no modification is needed on the macro itself, the association of the translations to the macro is done based on a convention of the form of the translation keys):
134 134  
135 -{{code}}
135 +{{code language='properties'}}
136 136  rendering.macro.<macro id>.name=Name of the macro, displayed in the macros list in the macros wizard
137 137  rendering.macro.<macro id>.description=Description of the macro, displayed as a help in the macros list in the macros wizard
138 138  
... ... @@ -144,7 +144,7 @@
144 144  
145 145  In our example, french translations would be something like this:
146 146  
147 -{{code}}
147 +{{code language='properties'}}
148 148  rendering.macro.hello.name=Macro pour dire bonjour
149 149  rendering.macro.hello.description=Ceci est une macro qui va dire "Bonjour" a l'utilisateur
150 150  rendering.macro.hello.parameter.greetUser.name=Personnaliser le message
... ... @@ -163,7 +163,7 @@
163 163  
164 164  Even in edit mode, the WYSIWYG editor will execute the macro and feed the result back into the document. If your macro use some JSX, these will not be loaded. But, if your macro produce some Javascript that use those JSX or manipulate the document's DOM (injecting new elements, moving existing elements, removing elements, etc.), you may want to protect the content in WYSIWYG edit mode in order to prevent the performed transformation to get saved. Here is how you can prevent this behavior:
165 165  
166 -{{code language="velocity"}}
166 +{{code language='velocity'}}
167 167  {{velocity}}
168 168  #if("$xcontext.action" != "edit")
169 169  {{html}}
... ... @@ -181,7 +181,7 @@
181 181  
182 182  == WYSIWYG editing of macro content or parameter ==
183 183  
184 -As specified above you can use the dedicated macros {{code language="none"}}{{wikimacrocontent/}}{{/code}} and {{code language="none"}}{{wikimacroparameter name="foo"/}}{{/code}} to allow the users of your macro to be able to edit the values of the macro directly in the WYSIWYG editor once the macro is inserted.
184 +As specified above you can use the dedicated macros {{code language='none'}}{{wikimacrocontent/}}{{/code}} and {{code language='none'}}{{wikimacroparameter name="foo"/}}{{/code}} to allow the users of your macro to be able to edit the values of the macro directly in the WYSIWYG editor once the macro is inserted.
185 185  Note that this is currently only possible if you specified that the macro content (or parameter) type is ##WIKI## type.
186 186  
187 187  {{info}}
... ... @@ -194,7 +194,7 @@
194 194  
195 195  * See all bindings in [[the reference documentation page>>doc:extensions:Extension.WikiMacroStore.WebHome||anchor="HBindings"]].
196 196  * 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:(((
197 -{{code language="groovy"}}
197 +{{code language='groovy'}}
198 198  {{groovy}}
199 199  import java.util.Collections;
200 200  import org.xwiki.rendering.listener.Link;
... ... @@ -214,7 +214,7 @@
214 214  {{/code}}
215 215  )))
216 216  * 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 -{{code language="velocity"}}
217 +{{code language='velocity'}}
218 218  {{velocity output="no"}}
219 219  ## get the macro content in a velocity string
220 220  #set($wikiresult = $wikimacro.content)
... ... @@ -236,7 +236,7 @@
236 236  
237 237  There is a common pitfall for using optional paramters. The following macro code contains a not so obvious bug:
238 238  
239 -{{code languege="velocity"}}
239 +{{code languege='velocity'}}
240 240  {{velocity}}
241 241  #set($greetUser=$xcontext.macro.params.greetUser)
242 242  #if ("true" == $greetUser && "XWiki.XWikiGuest" != "$xcontext.user" )
... ... @@ -249,7 +249,7 @@
249 249  
250 250  If we invoke it twice in a row:
251 251  
252 -{{code}}
252 +{{code language='none'}}
253 253  {{hello greetUser="true" /}}
254 254  {{hello /}}
255 255  {{/code}}
... ... @@ -261,6 +261,6 @@
261 261  
262 262  So in order to get around it, you can use:
263 263  
264 -{{code}}
264 +{{code language='none'}}
265 265  #set($greetUser="$!xcontext.macro.params.greetUser")
266 266  {{/code}}

Get Connected