我试图使用动态布局与翡翠和快车。我见过很多其他的方法,但从来没有办法干净利落的。
我的应用程序将有很多种模板,包括动态的其他模板。就像我的应用程序keystone,所以没有它我就不能走得更远.
下面是一个示例(3种模板类型):template_1 template_2 template_3
template_1包括template_2和其他template_3
所以如果它是静态的,我会这样做:
# template.coffee
exports.index = (req, res) ->
res.render 'template_1'
# template 1
Some HAML content
block content
div.block
include template_2
div.block
include template_3但是,我想给出要通过局部变量使用的模板列表:
所以,我想做这样的事
# template.coffee
exports.index = (req, res) ->
res.render 'template_1', {
template_list: [
'template_2',
'template_3'
]
}
# template 1
Some HAML content
block content
- each current_template in template_list
div.block
include current_template或
# template 1
Some HAML content
block content
- each current_template in template
div.block
include #{current_template}但不起作用。在包含或将扩展为字符串之后,它需要任何内容.
似乎玉石是事先编好的。
那么,是否有可能制造动态夹杂呢?或者是部分?还是动态布局?
谢谢你的帮助。
发布于 2015-01-12 22:36:04
考虑在客户端使用jadeify:https://github.com/domenic/jadeify,如果您也在使用browserify的话。
您可以这样做:
var template = require("./template.jade");
document.getElementById("my-thing").innerHTML = template({
localVar: "value",
anotherOne: "another value"
});https://stackoverflow.com/questions/18017851
复制相似问题