gpt4 book ai didi

handlebars.js - 组装:注册 Handlebars 辅助函数

转载 作者:行者123 更新时间:2023-12-04 05:55:13 24 4
gpt4 key购买 nike

我正在使用 assemble 0.4.17 其中捆绑了 Handlebars 1.3.0。
我正在尝试添加一个自定义 Handlebars 助手,如文档所示 here .

所以我将它添加到我的 Gruntfile(在文件底部,在 module.exports = function(grunt) { 之外)

Gruntfile.js

module.exports.asdf = function (str)  {  return 'asdf here!'; };

并将其添加到
index.hbs
{{#asdf}}
bobo
{{/asdf}}

我建议 asdf here!会出现在生成的 html 中,但它不会,而是只打印一个空行。我也试过 module.exports.register = function (Handlebars, options)方法,但这也不起作用。我需要添加其他东西来添加这个 Handlebars 助手吗?

我是组装和咕噜声和 Handlebars 的新手,所以我可能只是错过了明显的

最佳答案

助手应该在另一个文件中声明并添加到 helpers汇编目标中的选项:

我的助手.js

module.exports.asdf = function (str) { return 'asdf here!'; };

Gruntfile.js
grunt.initConfig({
assemble: {
options: {
helpers: ['./my-helper.js']
},
someTarget: {
...
}
}
});

关于handlebars.js - 组装:注册 Handlebars 辅助函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21503510/

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