Custom helpers

We added some custom helpers to the basic ones provided by Handlebars. They'll be helpful when building email templates for Snipcart. Here they are:


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'}}

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 }}

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 }}