Handlebars Adress Block custom function

Hello,
is it possible to register an Handlebars helper within an Adress Block hbs template?

I want to use a custom function without creating an additional script in the designer.

E.g.:

Handlebars.registerHelper('loud', function (aString) {
    return aString.toUpperCase()
})

<div class="myBox">
{{>myContent}}
</div>

{{#*inline "myContent"}}
{{loud OLC99MC_content}}
{{/inline}}

For this specific example you may want to use our Format helpers, try:

{{upperCase OLC99MC_content}}

For more info see: Format Helpers

Sorry for that bad example, of course there is a format helper. It is rather a general question whether custom functions can be entered within an hbs template.

After some research I also found a format helper to achieve leading zero in german postage code.

{{number OLC70Postcode "00000"}}

In the first place I tried to create a custom function to use padStart().

But it is not possible to use custom helpers in the Address Block hbs template?
In the above case it would be fine to check if the country is empty or ‘deutschland’ or ‘germany’ or ‘de’. Only if one of these cases is true I want to pad. The easiest way to do this would of course be to use a custom JavaScript function.

PS: I love that Address Block feature and want to use it for different use cases beyond an address.

I’m afraid you need a control script. It’s currently not possible to register a custom helper from within a Handlebars partial or address block template.

How about adding logic using handlebars? Think the following would work for your case:

{{#if or (not OLC60Country) (eq 'deutschland' lowerCase OLC60Country) (eq 'germany' lowerCase OLC60Country) }}
<p>{{number OLC70Postcode "00000"}}</p>
{{/if}}
1 Like

Hi Erik,
thanks a lot for that code snippet. For that specific case it is perfect. I have to dive deeper into the handlebars logic!

1 Like