发布于 2016-05-16 15:31:16 | 441 次阅读 | 评论: 0 | 来源: PHPERZ

Velocity有两种方式从外部引入文件:包括和解析。

1    包括

#include脚本元素允许模板设计者导入本地文件,然后插入到#include指令定义的位置。文件的内容通过模板引擎渲染。由于安

全原因,文件只能包含在TEMPLATE_ROOT。

#include("one.txt")

#include指令引用的文件被封闭在双引号中。如果多个文件被include,应该通过逗号分隔。

#include("one.gif","two.txt","three.htm")

可以使用变量替换文件名作为参数。

#include("greetings.txt", $seasonalstock)

2    解析

#parse脚本元素允许模板设计者导入包含VTL的本地文件。Velocity将解析VTL并渲染模板。

#parse("me.vm")

像#include指令一样,#parse可以传入一个变量而不是模板。任意引用的模板必须在TEMPLATE_ROOT中。和#include指令

不同,#parse只需要一个参数。

VTL模板可以在模板中递归使用#parse引用。velocity.properties中的directive.parse.max.depth属性允许用户自定义最大递

归数,默认设置为10。(如果velocity.properties文件中没有出现directive.parse.max.depth,Velocity将默认设置为10)。

Count down.

#set( $count = 8 )

#parse( "parsefoo.vm" )

All done with dofoo.vm!

引用的模板:

$count

#set( $count = $count - 1 )

#if( $count > 0 )

    #parse( "parsefoo.vm" )

#else

    All done with parsefoo.vm!

#end

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务