Email template custom helpers

On top of the standard Handlebars.js syntax, Snipcart email templates expose a set of custom helpers for formatting values and conditional rendering.

Accessing your data

Every template receives objects such as order, settings, and message. These are documented as reusable types — see Settings for store settings (signature, business address, logo, …) and the Template data reference for the full list of objects and fields. The helpers below operate on that data.

Formatting helpers

These format a value for display.

  • money — formats a monetary value using your account's currency settings.
    {{ money order.summary.total }}
  • date — formats a date (default yyyy-MM-dd); pass a second argument for a custom format. Dates are converted to your account's time zone.
    {{ date order.completionDate 'yyyy-MM-dd HH:mm:ss' }}
  • cleanHtml — sanitizes a value and renders it as HTML.
    {{ cleanHtml this.description }}
  • displayJsonValue — reads a value out of a JSON object by key (pass additional keys to drill into nested objects).
    {{ displayJsonValue order.metadata "key" }}
  • sum — adds its numeric arguments and outputs the total.
    {{ sum order.summary.total order.summary.subtotal }}
  • sum_money — same as sum, but formats the total as a monetary value.
    {{ sum_money order.summary.total order.summary.subtotal }}

Conditional helpers

Block helpers that render their inner block when the condition is met (each supports an {{ else }} branch).

  • if_eq — renders when all arguments are equal.
    {{ #if_eq order.paymentMethod 'CreditCard' }}
      Paid by credit card.
    {{ else }}
      Paid with {{ order.paymentMethod }}.
    {{ /if_eq }}
  • if_not_eq — renders when the arguments are NOT equal (the inverse of if_eq).
    {{ #if_not_eq order.summary.discountInducedTaxesVariation 0 }}
      Taxes were adjusted by a discount.
    {{ /if_not_eq }}
  • has_any — renders when an array contains at least one element.
    {{ #has_any order.items }}
      Your order:
    {{ else }}
      No items.
    {{ /has_any }}
  • contains — renders when an array contains a specific value.
    {{ #contains this.categories 'Cat1' }}
      In category Cat1.
    {{ /contains }}
  • has_items_from_category — renders when the order contains at least one item in the given category.
    {{ #has_items_from_category order.items 'Cat1' }}
      Contains an item from Cat1.
    {{ /has_items_from_category }}
  • has_downloadable_items — renders when the order contains at least one downloadable (digital) item.
    {{ #has_downloadable_items order.items }}
      Your download links are below.
    {{ /has_downloadable_items }}
  • has_shippable_items — renders when the order contains at least one shippable item.
    {{ #has_shippable_items order.items }}
      Shipping details:
    {{ /has_shippable_items }}
  • is_absolute_url — renders when a value is an absolute URL (starts with http:// or https://).
    {{ #is_absolute_url this.image }}
      <img src="{{ this.image }}" />
    {{ /is_absolute_url }}

Was this article helpful?