Closed mamzellejuu closed 10 years ago
I don't have any examples handy - what trouble are you having?
On Fri, May 30, 2014 at 12:30 PM, mamzellejuu notifications@github.com wrote:
Hi,
do you have example how helpers need to be formated to be functionnal ?
Reply to this email directly or view it on GitHub: https://github.com/patrickkettner/grunt-compile-handlebars/issues/23
Find the solution, need to name the file the name of the helper name
Hi there,
I'm also having troubles with helpers. Everything runs fine until I try to include them.
I have a very simple helper, howdy.js
Handlebars.registerHelper("howdy", function(){
return "howdy";
});
My grunt file looks like
'compile-handlebars': {
dist: {
template: '<%= config.src %>/templates/**/*.hbs',
templateData: '<%= config.src %>/data/**/*.json',
partials: '<%= config.src %>/partials/**/*.hbs',
helpers: '<%= config.src %>/helpers/**/*.js',
output: '<%= config.dist %>/*.html',
},
},
When I run Grunt, I get the error, Running "compile-handlebars:dist" (compile-handlebars) task Warning: Handlebars is not defined Use --force to continue."
Everything runs fine if I remove the helpers option in the grunt file, but then I can't use helpers. Any ideas?
Hey @ryan-ludwig!
Seems like your handlebars helper isn't including handlebars.
By default, you only need to export a function matching the function signature of a handlebars helper.
that means rather than
Handlebars.registerHelper("howdy", function(){
return "howdy";
});
you can have a file named howdy.js
, that looks like
module.exports = function() {
return "howdy";
};
alternatively , require
ing handlebars in your helper file should work,
var Handlebars = require('handlebars');
Handlebars.registerHelper("howdy", function(){
return "howdy";
});
though I honestly haven't tried that previously, and can't check right now (on a mobile).
Thanks a lot for the explanation @patrickkettner! Worked great.
Its a pleasure! Happy to help
On Fri, Jul 25, 2014 at 9:47 PM, Ryan Ludwig notifications@github.com wrote:
Thanks a lot for the explanation @patrickkettner! Worked great.
Reply to this email directly or view it on GitHub: https://github.com/patrickkettner/grunt-compile-handlebars/issues/23#issuecomment-50219936
Hi,
do you have example how helpers need to be formated to be functionnal ?