public class RenderDirective extends Directive
两种用法:
1:只传入一个参数,参数可以是 String 常量,也可以是任意表达式
#render("_hot.html")
#render(subFile)
2:传入任意多个参数,除第一个参数以外的所有参数必须是赋值表达式,用于实现参数传递功能
#render("_hot.html", title = "热门新闻", list = newsList)
上例中传递了 title、list 两个参数,可以代替父模板中的 #set 指令传参方式
并且此方式传入的参数只在子模板作用域有效,不会污染父模板作用域
这种传参方式有利于将子模板模块化,例如上例的调用改成如下的参数:
#render("_hot.html", title = "热门项目", list = projectList)
通过这种传参方式在子模板 _hot.html 之中,完全不需要修改对于 title 与 list
这两个变量的处理代码,就实现了对 “热门项目” 数据的渲染
| 构造器和说明 |
|---|
RenderDirective() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
exec(Env env,
Scope scope,
Writer writer) |
void |
setExprList(ExprList exprList)
指令被解析时注入指令参数表达式列表,继承类可以通过覆盖此方法对参数长度和参数类型进行校验
|
getLocation, hasEnd, setLocation, write, writeCopyright © 2017. All rights reserved.