Handlebars Helpers
Courier's custom Handlebars helpers for use in email template overrides and custom brand templates.
The default Handlebars helpers can be found here.
Check out our common use cases documentation on details on how to use these functions. Don't see a custom handlebars helper you need in the list? Share your use case.
Courier Handlebars Helpers
Logic
and
Returns true
if all arguments are truthy, false
if one argument is falsy, and true
if no arguments
Parameters
input
0
Note: Data and profile can have booleans.
Example:
condition
Use the if statement to specify a block of code to be executed if a condition is true. Will throw an error if the operator is unsupported.
- Require two operands separated by an operator.
- Run the appropriate operation on the operands.
Parameters
input
0
Note: Data and profile can have booleans.
Example:
conditional
- Loops through all arguments and ensures all are truthy if using the "and" logical operator.
- Loops through all arguments and ensures one is truthy if using the "or" logical operator.
- Returns true if the conditions passed, false otherwise (use #unless helper to hide content if condition passes).
Parameters
input
0
Note: Data and profile can have booleans.
not
Return false
if the argument is truthy. Returns true
if argument is false
, undefined
, null
, ""
, 0
, or []
Parameters
input
Example
or
Returns true
if one argument is truthy, false
if all argument are falsy, and false
if no arguments.
Parameters
input
0
Note: Data and profile can have booleans.
Data
default
Returns the value
if it is not nullish.
Parameters
input
0
Note: Data and profile can have booleans.
Example:
each
Iterates over a list. Inside the block, you can use this
to reference the element being iterated over.
Parameters
input
0
Example:
"data": {
"people": [
{
"name": "Rod"
},
{
"name": "TK"
},
{
"name": "Suhas"
}
]
}
This is a modified version of this Handlebars helper.
path
Use the variable handler to resolve a JSONPath
, and returns the resolved value, similar to var. Returns undefined if the value was not found.
Parameters
input
Example:
set
Set the value of a variable specified by name
. The top level names cannot start with brand
, data
, event
, profile
, recipient
, urls
Parameters
name
input
Example:
var
Uses the variable handler to resolve a JSONPath
, and returns the resolved value, similar to path. Returns the variable reference as a string {data.doesNotExist}
if the value was not found.
Parameters
input
Example:
with
This helper is a modified version of the Handlebars with
helper.
Sets the variable scope when rendering the block content.
Parameters
input
Example:
when run in this context
{
person: {
firstname: "Marty",
lastname: "Banks"
}
}
String
capitalize
Returns the capitalized first character of a given string.
Parameters
input
Example
concat
Stringifies all arguments and joins them using the provided separator. Should use null
string for the separator by default and should return a null string if no arguments.
Parameters
input
0
Example
format
Returns a formatted string given a format and set of arguments.
Parameters
input
0
Example:
datetime-format
Returns a formatted date string, can be set to a user IANA Timezone This helper will throw if an invalid date is provided.
Parameters
input
0
Examples
See full list of format options along with an additional option %p to add am, pm
trim-left
Removes whitespace from the beginning of a string, without modifying the original string.
Parameters
input
Example:
trim-one-char-right
This helper is for dealing with the following escaping issue.
Returns the string with the last character removed.
Parameters
input
Example:
trim-right
Removes whitespace from the end of a string, without modifying the original string.
Parameters
input
Example:
trim
Removes whitespace from the beginning and end of a string, without modifying the original string.
Parameters
input
Example:
truncate
Truncates the string to the number of characters defined in the helper
Parameters
input
length
- (optional)
suffix
Example:
Math
abs
Return the magnitude of a number. This helper will throw an errow if it encounters a value that is not a number.
Parameters
input
Example
add
Returns the the sum of two operands. This helper will throw an error if it encounters an input value that is not a number.
Parameters
term
term
Example
ceil
Returns the least integer greater than or equal to the decimal number input. This helper will throw an errow if it encounters a value that is not a number.
Parameters
input
Example
divide
Returns the quotient of its operands where the left operand is the dividend and the right operand is the divisor. This helper will throw an errow if it encounters an input value that is not a number or if the divisor is 0
.
Parameters
dividend
divisor
Example
floor
Returns the largest integer less than or equal to a given number. This helper will throw an errow if it encounters a value that is not a number.
Parameters
input
Example
inc
Increase value by 1.
Parameters
input
Example:
mod
Returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.
This helper will throw an errow if it encounters an input value that is not a number or if the divisor is 0
.
Parameters
dividend
divisor
Usage:
Example
multiply
Returns the product of two operands. This helper will throw an errow if it encounters an input value that is not a number.
Parameters
multiplier
multiplicand
Example
round
Returns the value of a number rounded to the nearest integer. This helper will throw an errow if it encounters an input value that is not a number.
Parameters
input
Example
subtract (sub)
Returns the difference of two operands. This helper will throw an errow if it encounters an input value that is not a number.
Parameters
term
term
Example
SendWithUs Helpers
SendWithUs helpers are available to help ease migration from your existing Jinja templates to Courier rendered messages.
swu_datetimeformat
Returns a formatted date string. This helper will throw if an invalid date is provided.
Parameters
input
0
Examples
swu_iso8601_to_time
Returns an ISO-8601 date string as epoch milliseconds. This helper will throw if an invalid date is provided.
Parameters
input
Examples
swu_timestamp_to_time
Returns an Unix epoch timestamp (seconds) as a millisecond epoch time value. This helper will throw if an invalid unix epoch date is not provided.
Parameters
input
Examples
translate
Translates a string based on the key, profile locale and .po translations you have uploaded to Courier.
Parameters
key
args
(multiple, space separated arguments)domain
(only scoped to "default" right now)locale
(fetched automatically from profile right now)
Examples