赋值:
#set( $foo = "Velocity" )
关键字:
#if #elseif #else #end 判断语句
例子: #if($a==1)true enough#{else}no way!#end
#foreach() #end 循环语句
例子:#foreach( $key in $allProducts.keySet() )
<li>Key: $key -> Value: $allProducts.get($key)</li>
#end
#include 用于包括一些资源文件,当然include是不会去解析资源文件,这和#parse不同
例子: #include( "one.txt" )
#parse,用于解析并且包括相应的资源文件
例子: #parse( "me.vm" ),和主文件共享相应的Context
#stop,用于停止执行解析,并返回,主要用于调试功能。
宏(自定义方法):
#macro,类似于宏定义,用于自定义相应的标记。
如下定义了一段宏,用于输出表格中的列表
#macro( tablerows $color $somelist )
#foreach( $something in $somelist )
<tr><td bgcolor=$color>$something</td></tr>
#end
#end
在模版中,只需要使用#tablerows($color $somelist)就可以取代里面的代码了:
#set( $greatlakes = ["Superior","Michigan","Huron","Erie","Ontario"] )
#set( $color = "blue" )
<table>
#tablerows( $color $greatlakes )
</table>