【发布时间】:2012-11-28 14:58:52
【问题描述】:
我想通过 Backbone 在客户端使用 Jade 模板。我怎样才能做到这一点?
目前,我已成功配置 Backbone (Marionette) 以编译 Jade 模板以在其视图中使用:
Marionette.TemplateCache.prototype.compileTemplate = (tmplStr) ->
console.log "jade stuff: ", jade.compile(tmplStr)
return jade.compile(tmplStr)
“问题”是:我目前正在编写如下模板:
script(type="text/template", id="tmplMainView")
| h1= title
| p= content
注意管道 (|) 是为了防止 Jade 在服务器端尝试解释/解析它们。我怎样才能消除那些?
更新
也许我可以使用 jade --client 标志...但它提供了一个编译函数:例如
h1= title
变成
function anonymous(locals, attrs, escape, rethrow, merge) {
attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge;
var buf = [];
with (locals || {}) {
var interp;
buf.push('<h1>');
var __val__ = title
buf.push(escape(null == __val__ ? "" : __val__));
buf.push('</h1>');
}
return buf.join("");
}
这意味着我必须为每个模板有 1 个 Jade/编译 JS?我该如何使用它?另外我认为许多 JS 文件是一种缓慢的工作方式?但是由于模板函数都被命名为匿名,那么我怎样才能连接或以某种方式有效地使用它们呢?
【问题讨论】:
标签: node.js backbone.js express pug marionette