(1)概述
1.什么是template
在生成html的时候,其中可能有一部分数据是动态生成的,那么我们可以以模板为基础,将动态内容结合到模板中,最终输出整个html文档
2.什么是template service
模板引擎有多种,比如jsp、freemaker、velocity等,为了能够便于使用,于是webx提供了TemplateService,屏蔽了各个引擎之间的细节与区别,所以在使用的时候直接使用TemplateService即可
(2)使用
1.配置
<services:template searchExtensions="true">
<tpl-engines:velocity-engine templateEncoding="UTF-8" strictReference="false" path="/${component}/templates">
<global-macros>
<name>global/*.vm</name>
</global-macros>
<plugins>
<vm-plugins:escape-support defaultEscape="html">
<noescape>
<if-matches pattern="^control\." />
<if-matches pattern="^screen_placeholder" />
<if-matches pattern="^stringEscapeUtil\.escape" />
<if-matches pattern="^csrfToken\.(get)?(\w*)hiddenField" />
</noescape>
</vm-plugins:escape-support>
</plugins>
</tpl-engines:velocity-engine>
<tpl-engines:freemarker-engine templateEncoding="UTF-8" path="/${component}/templates" />
<tpl-engines:jsp-engine path="/${component}/templates" />
</services:template>
cacheEnabled:表示是否保存模板搜索的结果,默认值会根据productionMode改变
defaultExtension:表示模板的默认后缀
searchLocalizedTemplates:表示是否根据当前local,搜索最合适的localized模板
searchExtensions:表示是否让TemplateService搜索可用的模板名后缀
<2>velocity-engine配置
global-macros:用来定义全局宏
vm-plugins:表示velocity的插件配置
noescape:表示不转义。也就是velocity渲染时候,如果匹配了正则的内容,就不对这块内容进行转义