Custom helpers
We added some custom helpers to the basic ones provided by Handlebars. They'll be helpful when building email templates for Snipcart.
Formatting helpers
These helpers can be used to format values.
money
This helper can be used to format money amounts. They will use the currency defined in your account settings.
{{ money order.total }}
date
This helper can be used to format dates. The first parameter is the date itself, and the second, optional, is the date format.
{{ date order.completionDate }}
Usage with date format:
{{ date order.completionDate 'yyyy-MM-dd HH:mm:ss'}}
cleanHtml
This helper can be used to parse HTML markup. The only parameter accepted is the markup itself, which is sanitized and rendered directly in the template.
{{ cleanHtml this.description }}
displayJsonValue
This helper can be used to show a value from a JSON object such as order metadata. The first parameter is the JSON object itself and the second is the property name.
{{ displayJsonValue order.metadata "key" }}
Conditional helpers
These helpers can be used to display some information depending on a condition or trigger.
if_eq
This helper can be used to check if a value equals an expected value. The first parameter is the value, and the second, the expected value.
{{ #if_eq order.paymentMethod 'CreditCard' }}
<span>The payment method is Credit card!</span>
{{ else }}
<span>The payment method is not credit card, it is {{order.paymentMethod }}.</span>
{{ /if_eq }}
has_any
This helper can be used to make sure an array contains some elements.
{{ #has_any order.items }}
<span>Items contain some elements!</span>
{{ else }}
<span>Nothing in this...</span>
{{ /has_any }}
contains
This helper can be used to make sure an array contains a specific element.
{{ #contains this.categories 'Cat1' }}
<span>Categories contain 'Cat1'</span>
{{ else }}
<span>Doesn't contain 'Cat1' category.</span>
{{ /contains }}
is_absolute_url
This helper can be used if you need to make sure that a URL is absolute.
{{ #is_absolute_url this.url }}
<span>{{ this.url }} is an absolute URL.</span>
{{ else }}
<span>{{ this.url }} is NOT an absolute URL.</span>
{{ /is_absolute_url }}
sum
This helper can be used when you need to sum the amount of some fields.
<div>
{{ sum order.summary.total order.summary.subtotal }}
</div>
sum_money
This helper does the same thing as sum
but it will also format the amount to display a value in money.
<div>
{{ sum_money order.summary.total order.summary.subtotal }}
</div>