Liquid helpers
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.
| Keyword | Description |
|---|---|
{{ }} | Denotes rendering output of an object or variable. |
{% %} | Denotes logic and control flow. |
if/else/elsif | Conditional branching. |
case/when | Creates a switch statement to execute a particular block of code when a variable has a specified value. |
and/or | Add additional conditions to a tag. |
for | Repeatedly executes a block of code. |
assign | Creates a new named variable. |
capture | Captures the string inside of the opening and closing tags and assigns it to a variable. |
Knock-specific Liquid helpers
| Helper | Description | Example |
|---|---|---|
timezone | Takes an ISO 8601 timestamp and returns it in the IANA tz database timezone provided. | {{timestamp | timezone: "America/New_York"}} |
format_number | Takes an integer and formats it to the local number format of the locale provided to format_number helper. | {{ 10000 | format_number: "en" }} |
currency | Takes 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_currency | Takes 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" }} |
json | Takes a value and returns as a formatted JSON string. | {{ recipient | json }} |
pluralize | Takes 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" }} |
titlecase | Takes a string and reformats it into Title case. | {{ project_name | titlecase }} |
md5 | Takes a string and returns an md5 hash. | {{ recipient.id | md5 }} |
sha256 | Takes a string and returns an sha256 hash. | {{ recipient.id | sha256 }} |
hmac_sha256 | Takes a string and returns an hmac hash given a key provided to hmac_sha256 helper. | {{ recipient.id | hmac_sha256: "some-key" }} |
intersect | Returns 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