多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 12.6. 解析 \#parse 脚本元素允许页面设计员导入包含VTL的本地文件。 Velocity将解析和渲染指定的模板。 ``` #parse( "me.vm" ) ``` 就象 \#include 指令,\#parse 可以使用变量而不是一个实在的模板文件。\#parse 引用的模板文件必须包含的TEMPLATE_ROOT指定的目录之下。和 \#include 指令不一样, \#parse 只有一个参数。 VTL 模板templates can have #parse statements referring to templates that in turn have #parse statements. By default set to 10, the parse_directive.maxdepth line of the velocity.properties allows users to customize maximum number of #parse referrals that can occur from a single template. (Note: If the parse_directive.maxdepth property is absent from the velocity.properties file, Velocity will set this default to 10.) Recursion is permitted, for example, if the template dofoo.vm contains the following lines: ``` Count down. #set( $count = 8 ) #parse( "parsefoo.vm" ) All done with dofoo.vm! ``` It would reference the template parsefoo.vm, which might contain the following VTL: ``` $count #set( $count = $count - 1 ) #if( $count > 0 ) #parse( "parsefoo.vm" ) #else All done with parsefoo.vm! #end ``` After "Count down." is displayed, Velocity passes through parsefoo.vm, counting down from 8. When the count reaches 0, it will display the "All done with parsefoo.vm!" message. At this point, Velocity will return to dofoo.vm and output the "All done with dofoo.vm!" message.