Is it possible to pass a JavaScript object/hash into a Handlebars helper call? I\'d like to do something like this:
{{#
Solved. I did this:
Helper:
Handlebars.registerHelper('textField', function(options) {
var attributes = [];
for (var attributeName in options.hash) {
attributes.push(attributeName + '="' + options.hash[attributeName] + '"');
}
return new Handlebars.SafeString('');
});
And the template:
{{textField id="text_field_1" class="some-class" size="30" data-something="data value"}}
Help text here.
Per the documentation (bottom of the page), you can pass in a variable number of parameters to a helper method, and they will be available in options.hash (assuming "options" is a parameter to your helper method). And what's also nice about this is that you can use named parameters, and parameter order doesn't matter.