gpt4 book ai didi

handlebars.js - 带有斜杠的 Handlebars 模板中的部分会导致错误

转载 作者:行者123 更新时间:2023-12-04 18:18:18 26 4
gpt4 key购买 nike

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

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

如果我在部分名称中使用斜杠,如下所示:
{{> path/partialname}}

我得到错误
The partial path.partialname could not be found [...]/lib/handlebars/handlebars.runtime

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

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

最佳答案

我整理的解决方案:

// 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
})

关于handlebars.js - 带有斜杠的 Handlebars 模板中的部分会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11263075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com