变量定义
#set( $a = "Velocity" )
各种注释
## This is a single line comment.
#*
Thus begins a multi-line comment. Online visitors won't
see this text because the Velocity Templating Engine will
ignore it.
*#
#**
This is a VTL comment block and
may be used to store such information
as the document author and versioning
information:
@author
@version 5
*#
属性
$customer.Address
如果customer是一个Map则等于customer.get("Address") 或者相当于customer.getAddress();
当作方法来调用
$person.setAttributes( ["Strange", "Weird", "Excited"] )
属性查找规则
$customer.address, the sequence is
getaddress()
getAddress()
get("address")
isAddress()
索引
$foo[0] ## $foo takes in an Integer look up
$foo[$i] ## Using another reference as the index
$foo["bar"] ## Passing a string where $foo may be a Map
相当于foo.get(Integer)
正式表示
Jack is a $vice maniac.
Jack is a ${vice}maniac.
空输出
$!email
严格模式
setting the velocity configuration property 'runtime.references.strict' to true
那么会抛出异常。
简写
$data.getRequest().getServerName()
## is the same as
$data.Request.ServerName
## is the same as
${data.Request.ServerName}
if语句
#if( $XHTML )
#set( $br = "<br />" )
#else
#set( $br = "<br>" )
#end
for语句
#foreach( $mud in $mudsOnSpecial )
#if ( $customer.hasPurchased($mud) )
<tr>
<td>
$flogger.getPromo( $mud )
</td>
</tr>
#end
#end
#foreach( $foo in [1..5] )
$foo
#end
逃跑
#[[
#foreach ($woogie in $boogie)
nothing will happen to $woogie
#end
]]#
\$email
包含
#include( "one.gif","two.txt","three.htm" )
宏
#macro( callme $a )
$a $a $a
#end
#callme( $foo.bar() )