6

The Velocity user guide 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 : 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.

starwarswii
  • 2,187
  • 1
  • 16
  • 19
Vlad K.
  • 300
  • 3
  • 11

1 Answers1

11

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
  • 4,033
  • 2
  • 17
  • 15