2

我正在使用车把的运行时构建并尝试使用已注册的部分。我愿意:

Handlebars.registerPartial("path/partialname", Handlebars.templates["path/partialname"])

如果我在部分名称中使用斜杠,如下所示:

{{> path/partialname}}

我得到错误

The partial path.partialname could not be found [...]/lib/handlebars/handlebars.runtime

“/”似乎被替换为“。”

如何在不修改 Handlebars.registerPartial 调用的情况下在部分中使用“/”?多谢。

4

1 回答 1

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
})
于 2012-06-30T02:02:04.750 回答