发布于 2016-05-16 15:31:26 | 271 次阅读 | 评论: 0 | 来源: PHPERZ
#macro脚本元素允许模板设计者定义重复的VTL模板片段。宏调用在简单和复杂的场景中非常广泛。
定义宏:
#macro( d )
<tr><td></td></tr>
#end
调用宏:
#d()
定义有体的宏,$!bodyContent为宏体:
#macro( d )
<tr><td>$!bodyContent</td></tr>
#end
调用有体的宏:
#@d()Hello!#end
定义带参数的宏:
#macro( tablerows $color $somelist )
#foreach( $something in $somelist )
<tr><td bgcolor=$color>$something</td></tr>
#end
#end
调用带参数的宏:
#set( $greatlakes = ["Superior","Michigan","Huron","Erie","Ontario"] )
#set( $color = "blue" )
<table>
#tablerows( $color $greatlakes )
</table>