4

我正在使用assemble 0.4.17,它捆绑了车把 1.3.0。
我正在尝试添加此处记录的自定义车把助手。

所以我将它添加到我的 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)方法,但效果不佳。我需要添加其他东西来添加这个车把助手吗?

我是 Assemble 和 grunt 和车把的新手,所以我可能只是错过了明显的

4

1 回答 1

6

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

我的助手.js

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

Gruntfile.js

grunt.initConfig({
  assemble: {
    options: {
      helpers: ['./my-helper.js']
    },
    someTarget: {
      ...
    }
  }
});
于 2014-02-02T05:56:55.963 回答