【发布时间】:2020-10-30 12:42:59
【问题描述】:
在 Handlebars 中,我需要覆盖部分数据,这些数据的范围是 JS 对象。 index.hbs 文件呈现具有不同数据的多个部分,但模块属性需要在全局数据对象内限定范围。使用点符号覆盖部分属性无法编译。
索引.hbs
<body>
{{> User }}
{{> User user.name="laura" }} // fails to compile - how to overwrite?
</body>
用户.hbs
<div>
Name is: {{name}}
Location is: {{location}}
</div>
索引.js
import index from "Index.hbs";
import user_partial from "User.hbs";
data = {
user: {
name: "kevin",
location: "bar"
}
}
Handlebars.registerPartial(user, user_partial);
document.innerHTML = Handlebars.compile(index)(data);
【问题讨论】:
标签: javascript templates handlebars.js partials