tags:

views:

47

answers:

1

Hi,

a velocity syntax page -- http://velocity.apache.org/engine/devel/user-guide.html#Loops -- mentions a "Hashtable". However there's no mentioning how to create one in this language.

So if you could show how to do this -- so that I could write smth. like

#foreach( $key in $foo.keySet() )
    <li>Key: $key -> Value: $foo.get($key)</li>
#end

-- I'd greatly appreciate your help.

Thanks in advance!

// PS: my original problem is : http://stackoverflow.com/questions/3348029/mechanical-turk-cmd-line-tools-qualification-set-and-foreach-in-xml So please understand that I am not interested in learning Velocity -- I only need one quick hack if possible. Thanks.

+1  A: 

In Velocity you would use the #set directive to create a map. To relate it to your example you might do something like:

#set($foo = {
    "NEWS": "http://news.bbc.com",
    "SEARCH": "http://google.com"
})

Then your foreach example above will do exactly what you need.

Will Prescott
Many thanks, that's exactly what I was looking for!
mabooka
PS: how do I mark my question "answered"?
mabooka
Glad to be of assistance - there should be a checkbox to the left of the answer to 'accept' it
Will Prescott