Liquid helpers

A reference guide to help you work with the Liquid templating language in Knock.

The Knock template editor uses Liquid syntax for control flow and variable declaration. Here are a few of the most common Liquid keywords our customers use within Knock. For a complete reference guide, we recommend the excellent Liquid documentation.

KeywordDescription
{{ }}Denotes rendering output of an object or variable.
{% %}Denotes logic and control flow.
if/else/elsifConditional branching.
case/whenCreates a switch statement to execute a particular block of code when a variable has a specified value.
and/orAdd additional conditions to a tag.
forRepeatedly executes a block of code.
assignCreates a new named variable.
captureCaptures the string inside of the opening and closing tags and assigns it to a variable.
renderRenders a partial with the given key and attributes.

Knock-specific Liquid helpers

HelperDescriptionExample
timezoneTakes an ISO 8601 timestamp and returns it in the IANA tz database timezone provided. You can use the built-in timestamp template variable to reference the current datetime. When formatting with the date filter, we recommend using the timezone option on the date filter instead.{{ timestamp | timezone: "America/New_York"}}
dateThis filter has been extended to take an additional timezone option.{{ startDate | date: "%-I:%M %p %Z" , "America/New_York" }}
format_numberTakes an integer and formats it to the local number format of the locale provided to format_number helper.{{ 10000 | format_number: "en" }}
currencyTakes an integer and returns a USD formatted value with two decimal points. You can pass a currency type and a locale through to the currency helper to tell it which currency to use.{{ 10 | currency: “GBP”, "en" }}
rounded_currencyTakes an integer and returns a USD formatted value rounded to nearest whole number. You can pass a currency type and a locale through to the currency helper to tell it which currency to use.{{ 10.99 | rounded_currency: "GBP", "en" }}
jsonTakes a value and returns as a formatted JSON string.{{ recipient | json }}
pluralizeTakes an integer and a pluralize helper with two strings. If the integer is one, the helper returns the first string. If the helper is greater than one, it returns the second string.{{ total_actors | pluralize: "user", "users" }}
titlecaseTakes a string and reformats it into Title case.{{ project_name | titlecase }}
md5Takes a string and returns an md5 hash.{{ recipient.id | md5 }}
sha256Takes a string and returns an sha256 hash.{{ recipient.id | sha256 }}
hmac_sha256Takes a string and returns an hmac hash given a key provided to hmac_sha256 helper.{{ recipient.id | hmac_sha256: "some-key" }}
intersectReturns the intersection of two arrays (the elements common to both).{{ arr1 | intersect: arr2 }}

Localization parameters

A few of Knock's Liquid helpers (such as currency and format_number) take an optional locale parameter to format the output of the helper into a localized format. You can find a list of supported locales below. If we're missing a locale that you'd like us to support, please reach out.

Supported locales: af, ar, az, be, bg, bn, bs, ca, cs, cy, da, de, el, en, eo, es, et, eu, fa, fi, fr, gl, he, hi, hr, hu, id, is, it, ja, ka, km, kn, ko, lb, lo, lt, lv, mk, ml, mn, mr, ms, nb, ne, nl, nn, or, pa, pl, pt, rm, ro, ru, sk, sl, sq, sr, sw, ta, te, th, tr, tt, ug, ur, uz, vi, wo, zh