The Velocity Template

Let"s have a look at the Velocity template for our first example: tutorial-stock-quote1.vm It"s a very simple example of displaying live stock quotes from a web service. The stock quotes are returned in a collection of quote records, called $quotes. Also, the column headers are in a collection of strings called $columns.

Accessors get the attributes: symbol, price, change and volume. Also notice that there are some macros: #headerCell and #entryCell. The macros are defined in a common Velocimacro file that is shared across Jetspeed. Velocimacro are great for defining little snippets of templates that can be included into other templates.

services.VelocityService.velocimacro.library = GlobalMacros.vm

The macros in question are defined in the GlobalMacros.vm file. A macro definition takes parameters. Macros can include macros:

#macro (formCell $label $name $value) #formLabel("$label") #formTextField("$name" "$value") #end

Similarly, common snippets can simple be parsed into the template directly:

#parse ("/portlets/html/tree-row-browser.vm")