【发布时间】:2025-11-22 10:05:01
【问题描述】:
【问题讨论】:
【问题讨论】:
是的 - 你看过了吗:
此处的示例:https://github.com/BorisMoore/jsrender-node-starter 在服务器和浏览器中显示嵌套布局。例如,这一行
https://github.com/BorisMoore/jsrender-node-starter/blob/master/templates/layout-movies.html#L34 正在做服务器模板合成:{{include tmpl='./templates/movie-list.html'/}} 在 layout-movies 模板中。
您还可以根据(服务器)渲染时数据或上下文进行动态组合 - 因为您可以将tmpl=... 设置为任何表达式。例如:
{{include tmpl=type==='a' ? '.../a.html': '.../default.html'/}}或
{{include tmpl=~getTmpl(type)/}}~getTmpl() 是一个助手,你可以这样定义:
jsrender.views.helpers("getTmpl", function(type) {
switch (type) {
case "major":
return "./templates/major.html";
}
return "./templates/base.html";
});
如果需要,您可以让 ~getTmpl() 返回实际编译的模板,而不是模板的文件路径,例如通过编写
return jsrender.templates("./templates/major.html");
【讨论】: