Vlad K.
Vlad K.

Reputation: 320

Apache Velocity: hashtable?

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.

Upvotes: 6

Views: 4859

Answers (1)

Will Prescott
Will Prescott

Reputation: 4053

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.

Upvotes: 11

Related Questions