4

I'm using assemble 0.4.17 which has bundled handlebar 1.3.0.
I'm trying to add a custom handlebar helper as documented here.

So I added this to my Gruntfile (at the bottom of the file, outside of module.exports = function(grunt) {)

Gruntfile.js

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

And added this to
index.hbs

{{#asdf}}
  bobo
{{/asdf}}

And I would suggest that asdf here! would show up in the generated html, but it does not, instead only a blank line is printed. I also tried the module.exports.register = function (Handlebars, options) method, but this didn't work as well. Do I need to add something else to add this handlebar helper?

I'm new to Assemble and grunt and handlebar, so I might just be missing the obvious

jonschlinkert
  • 10,872
  • 4
  • 43
  • 50
hansaplast
  • 11,007
  • 2
  • 61
  • 75

1 Answers1

6

The helpers should be declared in another file and added to the helpers option in your assemble target:

my-helper.js

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

Gruntfile.js

grunt.initConfig({
  assemble: {
    options: {
      helpers: ['./my-helper.js']
    },
    someTarget: {
      ...
    }
  }
});
doowb
  • 3,372
  • 1
  • 17
  • 25
  • indeed, the helpers-option was missing, IMO this part is completely missing in [this docs page](http://assemble.io/docs/Custom-Helpers.html), all it has is a link to [options.helpers](http://assemble.io/docs/options-helpers.html) with no info that this actually needs to be added. – hansaplast Feb 02 '14 at 06:05
  • You're right. The docs aren't the best, but we're working on cleaning them up. If you have a good idea on explaining the configuration from you're experience, please consider submitting a pull request so we can improve the docs for others. – doowb Feb 02 '14 at 19:44