jetbrick-template-1.x 旧版文档请看这里:http://subchen.github.io/jetbrick-template/1x/

§和 Velocity 的比较

jetbrick-template 的指令和老牌的模板引擎 Velocity 是非常相似的。

§1. 语法差异

§2. 指令差异

velocity jetbrick-template 异同 功能 变化
${foo.bar}
$foo.bar
${foo.bar} 相同 输出占位符 jetbrick-template 大括号必需
$!{foo.bar}
$!foo.bar
$!{foo.bar} 不同 空值不显示源码 velocity 为空值不显示源码
jetbrick-template 改为HTML过滤输出
## ...
#* ... *#
## ...
#// ...
#-- ... --#
相似 注释 块注释格式不一样
#[[ ... ]]# #[[ ... ]]# 相同 不解析文本块
\# \$ \\ \# \$ \\ 相同 特殊字符转义
n/a #define(Type foo = bar) 新增 给变量声明类型
#set($foo = $bar) #set([Type] foo = bar) 相同 给变量赋值 可带类型声明
n/a #return ( obj ) 新增 返回子模板变量给父模板
#if($foo == $bar) #if(foo == bar) 相同 条件判断
#elseif($foo == $bar) #elseif(foo == bar) 相同 否定条件判断
#else #else 相同 否定判断
#end #end 相同 结束指令
#foreach($item in $list) #for(item : list)
#for(Type item : list)
相似 循环指令 改为Java格式,可以带类型声明
#break #break
#break(foo == bar)
相同 中断循环 可以直接带条件
n/a #continue
#continue(foo == bar)
新增 继续下一个循环 可以直接带条件
#stop #stop
#stop(foo == bar)
相同 停止模板解析 可以直接带条件
#macro($foo) #macro foo(...) 相似 可复用模板片段宏
#macro_name($) #call macro_name(...) 相似 调用模板片段宏 采用 #call, 更清晰
n/a #tag foo(...) 新增 自定义标签 jetbrick-template 允许自定义标签
#include("foo.txt") fileGet("foo.txt") 不同 读取文本文件内容 jetbrick-template 用扩展函数实现
#parse("foo.vm") #include("foo.jetx")
#include("foo.jetx", args)
相似 调用子模板 jetbrick-template 支持私有参数传递
#evaluate("${1 + 2}") n/a 不同 模板求值 jetbrick-tempate 不支持
n/a #options(...) 新增 模板选项 jetbrick-tempate 支持独立的模板选项