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/