How to register custom handlebars helper
Hi there,
is there a way how to register new custom Handlebars helper?
I've came to the handlebars engine limitation when I cannot use if helper inside multiply helper.
I've found workaround for that with custom helper, however I do not know how to register it.
My problem is described more deeply there: https://docs.celigo.com/hc/en-us/community/posts/360077629011-Not-able-to-use-if-condition-inside-sum-handlebar-s-helper?input_string=How%20to%20register%20custom%20handlebars%20helper
So I've created custom helper which is easy to use on the page tryhandlebarsjs.com or jsfiddle.com, but not able to use in celigo mapping:
Handlebars.registerHelper("ifThenElse", function (condition, ifTrue, ifFalse) {
return condition ? ifTrue : ifFalse;
});
You would then use the helper in your template as a Handlebars Subexpression, which allows you to nest helpers:
{{#if shipping_lines_1.price}}
{{multiply
(sum
(ifThenElse shipping_lines_1.tax_lines.[0].price shipping_lines_1.tax_lines.[0].rate 0)
(ifThenElse shipping_lines_1.tax_lines.[1].price shipping_lines_1.tax_lines.[1].rate 0)
(ifThenElse shipping_lines_1.tax_lines.[2].price shipping_lines_1.tax_lines.[2].rate 0)
(ifThenElse shipping_lines_1.tax_lines.[3].price shipping_lines_1.tax_lines.[3].rate 0)
)
100
}}
{{/if}}
Comments
Dominik Antalík: integrator.io does allow subexpressions, but it does not support registering custom handlebars helpers.
Custom helpers, as you've demonstrated, extend handlebars with JavaScript functions.
Instead of defining a customer helper, you have access to several integrator.io features for customizing data, such as transforms, filters, and JavaScript hooks.
Stephen Brandt, all of the methods you mention for "customizing data, such as transforms, filters, and JavaScript hooks." are prohibited and impossible in every paid Integration tile I've used in Celigo, they are only allowed in our custom flows. The ability to register Handlebars helpers would be very useful to me, since of course Handlebars helpers are allowed just about everywhere in the system.
Thanks, Dominik Antalík and Geoff Tipley. This thread is now located under enhancement requests to give other Community members visibility and the chance to upvote it.
Your request has already been noted among our customer-suggested features, and I'll try to update you if we're able to address it in a release.
Hi Stephen Brandt, any update on this request? Ability to register custom handlebars helper would be super helpful.
Thanks for adding your upvote, Thao, and so noted. If the request gets prioritized for an upcoming release, I'll be sure to update this thread.
Please sign in to leave a comment.