【发布时间】:2015-01-26 17:05:16
【问题描述】:
我正在使用 grunt-compile-handlebars 来编译我的把手,但我遇到的问题是,@root 对象在我使用后会发生变化
[...]
handlebars.compile(template);
template(context.data);
[...]
所以当我的 json 对象类似于
{
"template": "path/to/template",
"data": {
"greetings": {...}
}
}
这始终是我的@root 对象。
我有类似的东西:
var handlebars = require('../../node_modules/grunt-compile-handlebars/node_modules/handlebars') ;
module.exports = function(context) {
var template = handlebars.partials[context.template];
template = handlebars.compile(template);
return new handlebars.SafeString( template(context.data) );
};
{{helper .}}
现在我的@root 对象是:
"data": {
"greetings": {...}
}
有没有办法在调用template(...)时保留@root
注意:这是一个非常简化的示例。我知道我也可以使用{{>path/to/template .}}
【问题讨论】:
标签: handlebars.js handlebarshelper