Braces.SendGrid (Braces v0.1.0)

Copy Markdown View Source

The helpers of SendGrid's dynamic templates, which are Handlebars: render a SendGrid template as SendGrid sends it.

template =
  Braces.Handlebars.compile!(~S|{{#greaterThan (length cart) 0}}{{insert name "default=Customer"}}, | <>
    ~S|you left {{length cart}} items, {{formatDate saved_at "MMMM DD, YYYY h:mm A" "-0800"}}.| <>
    ~S|{{/greaterThan}}|)

Braces.Handlebars.render!(template, data, helpers: Braces.SendGrid)
  • {{#equals a b}} and {{#notEquals a b}}: 3 equals "3", as SendGrid compares them.
  • {{#greaterThan a b}} and {{#lessThan a b}}.
  • {{#and a b}} and {{#or a b}}, with two or more values. A value is false when it's missing, false, "" or 0.
  • {{length value}}: a string's length, as JavaScript counts it, or a list's; 0 for anything else.
  • {{insert value "default=Customer"}}: the value, or the default when it's missing or "".
  • {{formatDate date "MMMM DD, YYYY"}}, with an optional UTC offset such as "-0800": a DateTime, an ISO 8601 string, or milliseconds since 1970, as JavaScript's Date reads them. Tokens: YYYY, YY, MMMM, MMM, MM, M, DD, D, dddd, ddd, HH, H, hh, h, mm, m, ss, s, A, a, ZZ and Z.

The block helpers render {{else}} when their condition is false. #if, #unless, #each, #with, @root and the rest of Handlebars work as in Handlebars.js.

Summary

Functions

and(a, b, options)

and(a, b, c, options)

and(a, b, c, d, options)

equals(a, b, options)

formatDate(date, format, options)

formatDate(date, format, offset, options)

greaterThan(a, b, options)

insert(value, default, options)

length(value, options)

lessThan(a, b, options)

notEquals(a, b, options)

or(a, b, options)

or(a, b, c, options)

or(a, b, c, d, options)