[xwiki-users] macros and lists
Hi, I figured out the macro capability. That is real powerful stuff. However, I failed to pass a list to macros. Is this a bug or by design? Stefan Bachert __________________________________________________ Do You Yahoo!? Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.com
On Mon, Feb 22, 2010 at 10:50, stefan bachert <[email protected]> wrote:
Hi,
I figured out the macro capability. That is real powerful stuff.
However, I failed to pass a list to macros. Is this a bug or by design?
It depends what you mean exactly by "pass a list to macros".
Stefan Bachert
__________________________________________________ Do You Yahoo!? Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.com _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
Ok, let's go into details. I want to create a macro which build a <select> with its <option> tag. Let call them {{buildSelect values=.. /}} For the option items I need a list of string values calling {{buildSelect values=["a","b","c"] /}} does not work. Display values in the macro just shows "[". OK, there is a workaround. Passing a string {{buildSelect values=["a|b|c"] /}} and applying $util.split works I guess this is a bug. -- View this message in context: http://n2.nabble.com/macros-and-lists-tp4611119p4617554.html Sent from the XWiki- Users mailing list archive at Nabble.com.
On Tue, Feb 23, 2010 at 09:07, Stefan Bachert <[email protected]> wrote:
Ok, let's go into details.
I want to create a macro which build a <select> with its <option> tag. Let call them {{buildSelect values=.. /}} For the option items I need a list of string values calling {{buildSelect values=["a","b","c"] /}} does not work. Display values in the macro just shows "[".
You need to escape " because it's part of the macro parameter syntax. {{buildSelect values=[~"a~",~"b~",~"c~"] /}} But are you sure you need " characters ? {{buildSelect values=a,b,c /}} should be enough Unless you want to interpret this string as velocity code in a wiki macro but it seems very dangerous (a user could put any velocity he wants as parameter of your macro).
OK, there is a workaround. Passing a string
{{buildSelect values=["a|b|c"] /}} and applying $util.split works
I guess this is a bug. -- View this message in context: http://n2.nabble.com/macros-and-lists-tp4611119p4617554.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
On Feb 23, 2010, at 10:07 AM, Thomas Mortagne wrote:
On Tue, Feb 23, 2010 at 09:07, Stefan Bachert <[email protected]> wrote:
Ok, let's go into details.
I want to create a macro which build a <select> with its <option> tag. Let call them {{buildSelect values=.. /}} For the option items I need a list of string values calling {{buildSelect values=["a","b","c"] /}} does not work. Display values in the macro just shows "[".
You need to escape " because it's part of the macro parameter syntax.
{{buildSelect values=[~"a~",~"b~",~"c~"] /}}
But are you sure you need " characters ?
{{buildSelect values=a,b,c /}} should be enough
The normalized syntax is {{buildSelect values="a,b,c"/}} If you don't put the quotes around parameter values they are added automatically for you. That's why you'd get the following: {{buildSelect values="["a","b","c"]"/}} And this explains why you need to escape the quotes if you use them inside a parameter value. Right now AFAIK only strings are supported as parameter type when the macro is used in wiki syntax. Thanks -Vincent
Unless you want to interpret this string as velocity code in a wiki macro but it seems very dangerous (a user could put any velocity he wants as parameter of your macro).
OK, there is a workaround. Passing a string
{{buildSelect values=["a|b|c"] /}} and applying $util.split works
I guess this is a bug.
Hi Thomas, For me it looks that ALL parameter will be converted to STRING Let's go into concrete ------------ How to be defined ------------- {{velocity}} #set($list = $xcontext.macro.params.listX) list = $list #foreach($x in $list) item = $x #end {{/velocity}} ------------ How to apply ------------- {{velocity}} #set($list =["aha","oho"]) {{passList listX=$list /}} #set($list =["aha","oho"]) {{passList listX=list /}} #set($list ="aha oho") {{passList listX=$list /}} {{passList listX="aha|oho" /}} {{passList listX=["aha","oho"] /}} {{passList listX="aha","oho" /}} {{passList listX=[aha,oho] /}} {{passList listX=aha,oho /}} {{/velocity}} -------- this is the output ---------- list = [aha, list = list list = aha list = aha|oho list = [ list = aha list = [aha,oho] list = aha,oho ----------------------------------- Stefan Bachert -- View this message in context: http://n2.nabble.com/macros-and-lists-tp4611119p4617869.html Sent from the XWiki- Users mailing list archive at Nabble.com.
On Tue, Feb 23, 2010 at 10:33, Stefan Bachert <[email protected]> wrote:
Hi Thomas,
For me it looks that ALL parameter will be converted to STRING Let's go into concrete
------------ How to be defined ------------- {{velocity}} #set($list = $xcontext.macro.params.listX) list = $list #foreach($x in $list) item = $x #end {{/velocity}} ------------ How to apply ------------- {{velocity}}
#set($list =["aha","oho"]) {{passList listX=$list /}}
#set($list =["aha","oho"]) {{passList listX=list /}}
#set($list ="aha oho") {{passList listX=$list /}}
{{passList listX="aha|oho" /}} {{passList listX=["aha","oho"] /}} {{passList listX="aha","oho" /}} {{passList listX=[aha,oho] /}} {{passList listX=aha,oho /}}
{{/velocity}} -------- this is the output ---------- list = [aha,
list = list
list = aha
list = aha|oho
list = [
list = aha
list = [aha,oho]
list = aha,oho -----------------------------------
Stefan Bachert
-- View this message in context: http://n2.nabble.com/macros-and-lists-tp4611119p4617869.html Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Ok i see what is the issue here. xwiki/2.0 macro does not in any way support velocity/java objects. It's only wiki syntax which is parsed after the velocity block is interpreted so the only thing you can do is put a proper string in it it's then the macro itself job to parse each parameter value. The only ting you can do with velocity here is to generate the proper macro you could have written without velocity. A good trick to know what you are doing is to use wiki=false in the velocity macro, that way you can see what has been exactly generated after velocity interpretation and before wiki syntax parsing. -- Thomas Mortagne
On 02/23/2010 10:33 AM, Stefan Bachert wrote:
Hi Thomas,
For me it looks that ALL parameter will be converted to STRING Let's go into concrete
------------ How to be defined ------------- {{velocity}} #set($list = $xcontext.macro.params.listX) list = $list #foreach($x in $list) item = $x #end {{/velocity}} ------------ How to apply ------------- {{velocity}}
#set($list =["aha","oho"]) {{passList listX=$list /}}
Macros don't speak Velocity. This should never work as you expect it to. First, velocity is executed, and $list is printed, resulting in: {{passList listX=[aha, oho] /}} Then the parameters are normalized, resulting in {{passList listX="[aha," oho]="" /}} Thus the actual result, listX = "aha[".
#set($list =["aha","oho"]) {{passList listX=list /}}
Here velocity does not affect the macro in any way, since it does not contain any velocity code. It's important to understand that Velocity is not a central dogma in the wiki syntax anymore, it's just a scripting language that can be executed inside a {{velocity}} marker. Macros don't natively know about velocity, they don't use velocity variables in any way. So, again, velocity is executed, but this time nothing is printed, resulting in just the macro line: {{passList listX=list /}} which is normalized to {{passList listX="list" /}} and thus the "list" result.
#set($list ="aha oho") {{passList listX=$list /}}
After executing velocity, this becomes: {{passList listX=aha oho /}} normalized as: {{passList listX="aha" oho="" /}} thus listX = "aha"
{{passList listX="aha|oho" /}}
Nothing special, listX is the string "aha|oho"
{{passList listX=["aha","oho"] /}}
I don't know how exactly this gets normalized, but it starts as: {{passList listX="["
{{passList listX="aha","oho" /}}
{{passList listX="aha" oho="" /}}
{{passList listX=[aha,oho] /}}
Normalized as {{passList listX="[aha,oho]" /}}
{{passList listX=aha,oho /}}
Normalized as {{passList listX="aha,oho" /}} So, in conclusion, it's impossible to pass lists as macro parameter values, but not because it's a bug (macro parameters don't know velocity, and they don't use the same syntax), but because this is how we defined the behavior. The only workaround is to pass a string and split it in the macro code. If you think that this is an important requirement, you can propose it as an improvement of the upcoming xwiki/2.1 syntax.
{{/velocity}} -------- this is the output ---------- list = [aha,
list = list
list = aha
list = aha|oho
list = [
list = aha
list = [aha,oho]
list = aha,oho
-- Sergiu Dumitriu http://purl.org/net/sergiu/
If I can give my opinion, I think it would be more coherent if macro parameters were defined like class properties are (lists, strings, numbers, Dates, list of users or groups, and so on...). But it would not be a requirement for me, just an interesting improvement. And I'm not sure about how this could be done ... Maybe having a XWikiMacroParameterXxxClass for each property type Xxx ? At the end it's more the way data is entered by user that's interesting. Having a macro {{avatar}} in wich user can choose from a list of wiki users would definitely make macros even more extraordinary :) Of course the macros would have to accept the possible java types of the various properties types (strings, lists, integers...) so it would be a change in syntax. 2010/2/23 Sergiu Dumitriu <[email protected]>
If you think that this is an important requirement, you can propose it as an improvement of the upcoming xwiki/2.1 syntax.
On Wed, Feb 24, 2010 at 23:57, Jeremie BOUSQUET <[email protected]> wrote:
If I can give my opinion, I think it would be more coherent if macro parameters were defined like class properties are (lists, strings, numbers, Dates, list of users or groups, and so on...).
That's exactly how real (JAVA) macros are defined and what is supported by the WYSIWYG. It's just a temporary limitation of WIKI macros. (See http://platform.xwiki.org/xwiki/bin/view/DevGuide/RenderingMacroTutorial)
But it would not be a requirement for me, just an interesting improvement. And I'm not sure about how this could be done ... Maybe having a XWikiMacroParameterXxxClass for each property type Xxx ? At the end it's more the way data is entered by user that's interesting. Having a macro {{avatar}} in wich user can choose from a list of wiki users would definitely make macros even more extraordinary :) Of course the macros would have to accept the possible java types of the various properties types (strings, lists, integers...) so it would be a change in syntax.
2010/2/23 Sergiu Dumitriu <[email protected]>
If you think that this is an important requirement, you can propose it as an improvement of the upcoming xwiki/2.1 syntax.
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
Thanks, meanwhile I realized that some macros had this behaviour (toc...), and that is was because they are Java macros ... ;-) 2010/2/25 Thomas Mortagne <[email protected]>
On Wed, Feb 24, 2010 at 23:57, Jeremie BOUSQUET <[email protected]> wrote:
If I can give my opinion, I think it would be more coherent if macro parameters were defined like class properties are (lists, strings, numbers, Dates, list of users or groups, and so on...).
That's exactly how real (JAVA) macros are defined and what is supported by the WYSIWYG. It's just a temporary limitation of WIKI macros.
(See http://platform.xwiki.org/xwiki/bin/view/DevGuide/RenderingMacroTutorial)
But it would not be a requirement for me, just an interesting improvement. And I'm not sure about how this could be done ... Maybe having a XWikiMacroParameterXxxClass for each property type Xxx ? At the end it's more the way data is entered by user that's interesting. Having a macro {{avatar}} in wich user can choose from a list of wiki users would definitely make macros even more extraordinary :) Of course the macros would have to accept the possible java types of the various properties types (strings, lists, integers...) so it would be a change in syntax.
2010/2/23 Sergiu Dumitriu <[email protected]>
If you think that this is an important requirement, you can propose it as an improvement of the upcoming xwiki/2.1 syntax.
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (6)
-
Jeremie BOUSQUET -
Sergiu Dumitriu -
stefan bachert -
Stefan Bachert -
Thomas Mortagne -
Vincent Massol