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.
Apache Velocity first released in April 2001, is a Java-based template engine that provides a template language to reference objects defined in Java code. It aims to ensure clean separation between the presentation tier and business tiers in a Web application (the model–view–controller design pattern).
Velocity is a Java-based templating engine. It's an open source web framework designed to be used as a view component in the MVC architecture, and it provides an alternative to some existing technologies such as JSP. Velocity can be used to generate XML files, SQL, PostScript and most other text-based formats.
Developer file used by Velocity, a Java-based template engine; written using the Velocity Template Language (VTL); contains VTL statements inserted in a normal text document; often used for auto-generating Web source code and class skeletons.
VelocityContext(Context innerContext) Chaining constructor, used when you want to wrap a context in another. VelocityContext(Map<String,Object> context) Creates a new instance with the provided storage (and no inner context).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With