Getting Started with Velocity Templates - bahkified/Notes GitHub Wiki

##Dynamic Content

  • $var_name: use the value of the variable var_name from the view’s model. If var_name does not exist in the model, the string literal ‘$var_name’ is output.
  • $!var_name: use empty string if the variable is not found in the model.
  • #include(“dir/template.vm”): include the information from another view page. The Velocity engine will not parse this page.
  • #parse(“dir/template.vm”): include this view page in the current page. The page is parsed by the Velocity engine.
#if ( $condition )
  ...
#else
  ... 
#end

regular conditional block using Velocity syntax. To check for NULL values, you can use the condition: $!variable == "". Velocity will look for the variable in the view's model. If it is found, the value is put in place of the Velocity variable. If it is not found in the model, an empty string is substituted instead. *

#foreach( $element in $iterable )
  ...
#end

iterates over a list of objects. $iterable must be a Java iterable object, such as a List or an array.

##Resources