gpt4 book ai didi

handlebars.js - Handlebars 部分文件不清楚

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

所以我已经阅读了关于 Handlebars partials 的官方文档.
它指出:

In order to use a partial, it must be registered via Handlebars.registerPartial.

Handlebars.registerPartial('myPartial', '{{name}}')

This call will register the myPartial partial. Partials may be precompiled and the precompiled template passed into the second parameter.


不解释什么 {{name}}应该是当你没有预编译任何东西的时候。我不想注册内联模板,我将它们作为单独的文件放在 templates/partials 中,例如 templates/partials/_header.hbs .我只需要使用 gulp-handlebars 生成 HTML 作为构建过程的一部分.
该文档不包括如何将外部文件注册为模板(我认为这是在服务器端使用 Handlebars 时的标准情况)。
有人可以帮忙吗?

最佳答案

您引用的文档中的部分说:

Partials may be precompiled and the precompiled template passed into the second parameter.



这意味着您可以替换 '{{name}}'带有预编译的部分。这将要求您使用 -p 预编译部分。旗帜。

您可以避免所有这些,并在没有 -p 的情况下将模板和部分预编译在一起。旗帜。 (基本上将部分预编译为模板)。通过这样做,您不需要预先注册部分。
这样做的一个副作用是您需要添加 Handlebars.partials = Handlebars.templates;在您的代码处理任何模板或部分之前。

这是基于来自此 question 的信息.

关于handlebars.js - Handlebars 部分文件不清楚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48867218/

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