我正在尝试做一些从我看过的Assemble文档和其他 repos 中看起来相对简单的事情,但由于某种原因,我在注册 Handlebars 助手时遇到了问题。助手在 helpers > helper-classgrid.js
module.exports.register = function (Handlebars, options, params) {
Handlebars.register('classgrid', function (index, options) {
gridclass: function (index, options) {
if (index === 0 || index % 4 === 0) {
return options.fn(this);
}
return options.inverse(this);
};
};
我的 gruntfile 其中 config.helpers = helpers:
assemble: {
options: {
layoutdir: '<%= config.guts %>/templates/layouts/',
assetsDir: '<%= grunt.config.get("assets_dir") %>',
environmentIsProduction: '<%= grunt.config.get("environmentIsProduction") %>',
environmentIsDev: '<%= grunt.config.get("environmentIsDev") %>',
data: ['<%= config.content %>/**/*.json', '<%= grunt.config.get("environmentData") %>'],
helpers: ['<%= config.helpers %>/helper-*.js']
},
}
模板代码:
{{#classgrid @index}}
// do something here
{{/classgrid}}
现在,当我在我的 Handlerbars 模板中实现我的助手并运行包含 assemble 任务的 grunt 任务时,我得到了错误
Warning: Missing helper: 'classgrid' Use --force to continue.
我不确定我做错了什么,或者我是否必须为我的助手创建一个单独的 NPM 包,这似乎在 assemble 文档中建议。我查看了这两个似乎正在做我想做的事情的 repos
https://github.com/buildingblocks/bb-prototype-website/blob/master/Gruntfile.js https://github.com/ghost-town/layouts-example/blob/master/Gruntfile.js#L33