我正在使用把手的运行时版本并尝试使用已注册的部分。我这样做:
Handlebars.registerPartial("path/partialname", Handlebars.templates["path/partialname"])
如果我在部分名称中使用斜杠:
{{> path/partialname}}
我收到错误
The partial path.partialname could not be found [...]/lib/handlebars/handlebars.runtime
" /"似乎取代了"。"
我如何使用" /"在部分内部而不修改Handlebars.registerPartial调用?很多。
答案 0 :(得分:4)
我把解决方案放在一起:
// automaticly register all templates as partials, so we dont have to do it manually
// https://github.com/wycats/handlebars.js/issues/190
// also convert slashes to dots in the template name because this is how
// handlebars resolves partial names.
_.each(Handlebars.templates, function(val, key){
var key = key.replace(/\//g, ".")
Handlebars.partials[key] = val
})