patrickkettner / grunt-compile-handlebars

grunt plugin to compile static html from a handlebars plugin
MIT License
115 stars 29 forks source link

Missing helper #48

Closed hiulit closed 9 years ago

hiulit commented 9 years ago

I don't know how to properly use helpers...

I'm getting this message: Warning: Missing helper: 'times' Use --force to continue

I have the following code:

'compile-handlebars': {
    dev: {
        template: '<%= project.srcFilesViewsHBS %>',
        templateData: '<%= project.srcFilesContextHBS %>',
        helpers: '<%= project.srcFileHelpersHBS %>',
        output: '<%= project.srcDir %>**/*.html'
    }
}

And everything works but the helpers. I guess I'm not coding them right...

var Handlebars = require('handlebars');
// {{#times 12}}
//   <output>
// {{/times}}
module.exports.register = function (Handlebars, options)  {
    Handlebars.registerHelper('times', function(n, block) {
        var accum = '';
        for(var i = 0; i < n; ++i)
                accum += block.fn(i);
        return accum;
    });
};
patrickkettner commented 9 years ago

hey @hiulit!

assuming that the file for <%= project.srcFileHelpersHBS %> is the one you are showing, then the only oddity I see is that you should be setting module.exports to the function, not module.exports.register

let me know if you have any other issues