Reputation: 2551
So I have 2 helpers, #hex
works correctly when used separately, and #rgb
also works correctly when a color has been passed directly. However, ideally, I'd like to use my #hex
helper within the call to the #rgb
helper but I'm not having much luck. Here's what I have so far.
Helper within helper - Doesn't work as expected:
{{#rgb {{#hex color}}{{/hex}} -0.25}}
Example of what is expected of the above:
{{#rgb #abc123 -0.25}}
Is this achievable within handlebars or would it be easier if I wrote a new helper that included both my #rgb
helper and #hex
helper?
Upvotes: 0
Views: 2530
Reputation: 521
You can do this with parentheses rather than curly brackets:
{{helper1 (helper2 var1) var2}}
Example:
// dummy helpers
Handlebars.registerHelper('rgb', function(color, opacity) {
return color + ' ' + opacity;
});
Handlebars.registerHelper('hex', function(color) {
return color + 'hexified';
});
// now in template
var template = '{{rgb (hex color) -0.25}}';
Handlebars.compile(template)({color: 'green'});
//Outputs "greenhexified -0.25"
Upvotes: 5