Courier’s custom Handlebars helpers for use in email template overrides and custom brand templates.The default Handlebars helpers can be found here.
Courier Handlebars Helpers
Logic
and
Returnstrue if all arguments are truthy, false if one argument is falsy, and true if no arguments
Parameters
input
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.
input
condition helper supports various comparison operators for arithmetic evaluations:
==- Equal to!=- Not equal to>- Greater than<- Less than>=- Greater than or equal to<=- Less than or equal to
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).
input
not
Returnfalse if the argument is truthy. Returns true if argument is false, undefined, null, "", 0, or []
Parameters
input
or
Returnstrue if one argument is truthy, false if all argument are falsy, and false if no arguments.
Parameters
input
Data
default
Returns thevalue if it is not nullish.
Parameters
input
each
Iterates over a list. Inside the block, you can usethis to reference the element being iterated over.
Parameters
input
NOTEThis is a modified version of this Handlebars helper.
path
Use the variable handler to resolve aJSONPath, and returns the resolved value, similar to var. Returns undefined if the value was not found.
Parameters
input
set
Set the value of a variable specified byname. The top level names cannot start with brand, data, event, profile, recipient, urls
Parameters
nameinput
var
Uses the variable handler to resolve aJSONPath, 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
with
NOTEThis helper is a modified version of the Handlebars
with helper.input
String
capitalize
Returns the capitalized first character of a given string. Parametersinput
concat
Stringifies all arguments and joins them using the provided separator. Should usenull string for the separator by default and should return a null string if no arguments.
Parameters
input
format
Returns a formatted string given a format and set of arguments. Parametersinput
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. Parametersinput
INFOSee 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. Parametersinput
trim-one-char-right
INFOThis helper is for dealing with the following escaping issue.
input
trim-right
Removes whitespace from the end of a string, without modifying the original string. Parametersinput
trim
Removes whitespace from the beginning and end of a string, without modifying the original string. Parametersinput
truncate
Truncates the string to the number of characters defined in the helper Parametersinputlength- (optional)
suffix
Math
abs
Return the magnitude of a number. This helper will throw an error if it encounters a value that is not a number. Parametersinput
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. Parameterstermterm
ceil
Returns the least integer greater than or equal to the decimal number input. This helper will throw an error if it encounters a value that is not a number. Parametersinput
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 error if it encounters an input value that is not a number or if the divisor is0.
Parameters
dividenddivisor
floor
Returns the largest integer less than or equal to a given number. This helper will throw an error if it encounters a value that is not a number. Parametersinput
inc
Increase value by 1. Parametersinput
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 error if it encounters an input value that is not a number or if the divisor is0.
Parameters
dividenddivisor
multiply
Returns the product of two operands. This helper will throw an error if it encounters an input value that is not a number. Parametersmultipliermultiplicand
round
Returns the value of a number rounded to the nearest integer. This helper will throw an error if it encounters an input value that is not a number. Parametersinput
subtract (sub)
Returns the difference of two operands. This helper will throw an error if it encounters an input value that is not a number. Parameterstermterm
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. Parametersinput
swu_iso8601_to_time
Returns an ISO-8601 date string as epoch milliseconds. This helper will throw if an invalid date is provided. Parametersinput
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. Parametersinput
translate
Translates a string based on the key, profile locale and .po translations you have uploaded to Courier. Parameterskeyargs(multiple, space separated arguments)domain(only scoped to “default” right now)locale(fetched automatically from profile right now)