把手帮手:编译模板,并保持@root
问题描述:
我使用咕噜编译车把编译我的车把和我有问题,该@root
对象改变我用把手帮手:编译模板,并保持@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": {...}
}
有没有一种方法可以让我保持@root
打电话时template(...)
注:这是一个非常简单的例子。我知道,我还可以使用{{>path/to/template .}}
答
见https://github.com/wycats/handlebars.js/issues/945:
template(context, {data: {root: options.data.root}})