Velocity入门指南——第八章 导入外部文件
2015-12-04 00:00
274 查看
摘要: Velocity入门指南 导入外部文件
Velocity有两种方式从外部引入文件:包括和解析。
全原因,文件只能包含在TEMPLATE_ROOT。
#include("one.txt")
#include指令引用的文件被封闭在双引号中。如果多个文件被include,应该通过逗号分隔。
#include("one.gif","two.txt","three.htm")
可以使用变量替换文件名作为参数。
#include("greetings.txt", $seasonalstock)
#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
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
相关文章推荐
- Velocity入门指南——第三章 引用
- Velocity入门指南——第四章 引用严格模式
- Velocity入门指南——第九章 其它指令
- Velocity入门指南——第十章 宏调用
- Velocity入门指南——第七章 循环指令
- BestCoder Round #64 (div.2) HDOJ5587 Array(dfs)
- iOS开发常见问题(二)
- restful-webservice-interceptor
- 计算机存储结构以及方式
- Java length size
- mysql常用数据类型的使用方式--数值型
- mysql数据类型---数值型---int
- mysql常用数据类型的使用方式--日期时间型
- mysql中时间操作(不断完善)
- 使用Dockerfile构建支持SSH等服务的CentOS
- 短信开发的PDU格式
- jquery easyui datagrid 双击编辑某一个单元格
- 厦门巨游网络科技有限公司(HOTPOWER)承接游戏UI外包