KnockDocs

Reference: liquid helpers

This is a reference of common Knock variables, Liquid syntax, and Knock-specific liquid helpers that you can use within the Knock template editor.

Common Knock variables

When you build workflows in Knock, we auto-generate certain pieces of state (as a result of batch functions and other workflow steps) that you can use to control the copy you display to your end users in your notification templates.

VariableDescription
actorUser or Object schema properties of the actor that triggered the workflow (may be null).
actorsA list of up to 10 of the unique actors included within the batch, where each actor is a user or object with the properties available on your Knock schema (may be empty).
recipientUser schema properties of the actor that triggered the workflow.
activitiesA list of the activity objects included within the batch, where each activity equals the state sent across in your notify call, and also includes the actor who performed the message and a timestamp of when the activity occurred.
varsAccount and environment specific variables.
total_activitiesThe count of activities associated with a workflow run.
total_actorsThe count of unique actors associated with a workflow run.
timestampThe time in which the activity occurred, as an ISO-8601 datetime string.
workflowThe id, key, and categories of the current workflow.

Common Liquid keywords

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.

Knock-specific Liquid helpers

HelperDescriptionExample
timezoneTakes an ISO 8601 timestamp and returns it in the IANA tz database timezone provided.{{timestamp | timezone: "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" }}

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