End of support notice: On October 30, 2026, AWS will end support for Amazon Pinpoint. After October 30, 2026, you will no longer be able to access the Amazon Pinpoint console or Amazon Pinpoint resources (endpoints, segments, campaigns, journeys, and analytics). For more information, see Amazon Pinpoint end of support. Note: APIs related to SMS, voice, mobile push, OTP, and phone number validate are not impacted by this change and are supported by AWS End User Messaging.
Using message template helpers
With Amazon Pinpoint templates, customers can create reusable message templates based on the Handlebars.js language. Helpers provide a variety of features like formatting a price to a specific Region's currency or adding a time zone-based location. A helper can use a specific string or integer for the value or a specific Amazon Pinpoint message variable.
These are the categories of helpers, described in the following sections:
This section describes the built-in helpers provided by
Handlebars. For the full list, see Built-in
Helpers
-
each– Iterates a list.Note
The maximum list size is 15 items.
-
if– Evaluates a statement.
- each
-
Iterates a list. This helper uses only a block statement. You can optionally:
-
Pass
@indexin the request to reference the current loop index. -
Use the
thishelper to reference the current element being iterated. -
Return the helper response in a list, using the
<li>tag.
Usage
{{#eachvalue}}Value at position
{{@index}}is{{this}}.{{else}}Condition is false.
{{/each}}eachmust be prefaced with a pound sign (#) and conclude with a closing{{/each}}in the block statement.Example
In this example,
eachis used to return a list of a user's favorite colors. For afalse, anelsestatement is returned. If the request is this:{{#each User.UserAttributes.FavoriteColors}}<li>{{this}}</li>{{else}}You have no favorite colors.{{/each}}returns-
red -
blue -
yellow
for a true statement.
-
- if
-
Evaluates whether something is true and returns a response based on the evaluation.
Usage
{{#ifvalue}}Value isn't undefined
{{else}}Value is undefined
{{/if}}ifmust be prefaced with a pound sign (#) and conclude with a closing{{/if}}in the block statement.Example
In this example, the
ifhelper is used to evaluate whether a user's first name. If the name is found, a greeting is returned that passes the user's first name in the response. Otherwise, theelsestatement returns an alternative greeting.{{#if User.UserAttributes.FirstName.[0]}}Hello{{User.UserAttributes.FirstName.[0]}},{{else}}Hello,{{/if}}returns
Hello, Janeif theifhelper is true.
This section describes the conditional helpers.
Conditional helpers can be used on either a single line or in a block statement.
You can customize the response regardless of which helper method you use. You can
pass additional conditional helpers within both single line and block statements.
The following conditional helpers show usage first for a single line and then a
block statement using an optional else clause. These are the
conditional helpers:
-
and– Compares whether all passed elements are equal. -
eq– Tests whether two elements are equal. -
gt– Tests whether one element is greater than another. -
gte– Tests whether one element is greater than or equal to another. -
if– Evaluates whether something is true. -
lt– Tests whether one element is less than another. -
lte– Tests whether one element is less than or equal to another. -
neq– Evaluates whether two elements are not equal. -
not– Inverts the response of a Boolean operation. -
or– Compares whether any of the elements in the argument are equal.
- and
-
Compares whether all elements passed in an argument are equal, and then returns the response based on the result. This helper can be used for non-Boolean values. You must pass at least two elements for the condition.
Usage
-
{{andvalueavaluebvaluecvaluedyes='y' no='n'}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#andvalueavalueb}}Condition is true.
{{else}}Condition is false.
{{/and}}andmust be prefaced with a pound sign (#) and conclude with a closing{{/and}}in the block statement.
Example
In this example,
eqis used within theandblock statement to determine whether both strings passed for theLocation.CityandLocation.Countryattributes are true. If both conditions are equal, then a true statement is returned. If either of those attributes are false, then anelsestatement is returned.{{#and (eq Location.City "Los Angeles") (eq Location.Country "US")}}You live in Los Angeles and the US.{{else}}You don’t live in Los Angeles and the US.{{/and}} -
- eq
-
Tests whether two elements are equal or if the value of one element is equal to a passed string.
Usage
-
{{eqvalueavaluebyes='y' no='n'}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#eqvalueavalueb}}Condition is true.
{{else}}Condition is false.
{{/eq}}eqmust be prefaced with a pound sign (#) and conclude with a closing{{/eq}}in the block statement.
Example
In this example,
eqis used to evaluate whether the value ofUser.UserAttributes.FavoriteColors.[0]isRed. If the response istrue, a true statement is returned. If the response isfalse, then anelsestatement is returned.{{#eq User.UserAttributes.FavoriteColors.[0] "red"}}Your favorite color is red.{{else}}You don't like red.{{/eq}} -
- gt
-
Tests whether the value of one element is greater than another.
Usage
-
{{gtvalueavaluebyes='y' no='n'}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#gtvalueavalueb}}Condition is true.
{{else}}Condition is false.
{{/gt}}gtmust be prefaced with a pound sign (#) and conclude with a closing{{/gt}}in the block statement.
Example
In this example, the helper compares the value of
User.UserAttributes.UserAge.[0]attribute against a string17, to verify whether the user's age is greater than 17. If the response istrue, a true statement is returned. If the response isfalse, then anelsestatement is returned.{{#gt User.UserAttributes.UserAge.[0] "17"}}You are old enough to rent a car.{{else}}You are not old enough to rent a car.{{/gt}} -
- gte
-
Tests whether the value of one element is greater than or equal to another.
Usage-
{{gtevalueavaluebyes='y' no='n'}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#gtevalueavalueb}}Condition is true.
{{else}}Condition is false.
{{/gte}}getmust be prefaced with a pound sign (#) and conclude with a closing{{/gte}}in the block statement.
Example
In this example, the helper compares the
User.UserAttributes.UserAge.[0]attribute against a string18, to verify whether the user's age is greater than or equal to 18. If the response istrue, a true statement is returned. If the response isfalse, then anelsestatement is returned.{{#gte User.UserAttributes.UserAge.[0] "18"}}You are old enough to rent a car.{{else}}You are not old enough to rent a car.{{/gte}} -
- if
-
Evaluates whether something is true and returns a response based on the evaluation.
Usage
-
{{#ifvalue}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#if}}valueCondition is true.
{{else}}Condition is false.
{{/if}}ifmust be prefaced with a pound sign (#) and conclude with a closing{{/if}}in the block statement.
Example
In this example, the helper is used to evaluate whether a user's first name. If the name is found, a greeting is returned that passes the user's first name in the response. Otherwise, the else statement returns an alternative greeting.
{{#if User.UserAttributes.FirstName.[0]}}Hello{{User.UserAttributes.FirstName.[0]}},{{else}}Hello,{{/if}}returns
Hello Jane,if the helper is true. -
- lt
-
Tests whether the value of one element is less than the value of another.
Usage
-
{{ltvalueavaluebyes='y' no='n'}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#ltvalueavalueb}}Condition is true.
{{else}}Condition is false.
{{/lt}}ltmust be prefaced with a pound sign (#) and conclude with a closing{{/lt}}in the block statement.
Example
In this example, the helper compares the
User.UserAttributes.UserAge.[0]attribute against a string18, to verify whether the user's age is less than 18. If the response istrue, a true statement is returned. If the response isfalse, then anelsestatement is returned.{{#lt User.UserAttributes.UserAge.[0] "18"}}You are not old enough to rent a car.{{else}}You are old enough to rent a car.{{/lt}} -
- lte
-
Tests whether the value of an element is less than or equal to another.
Usage
-
{{ltevalueavaluebyes='y' no='n'}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#ltevalueavalueb}}Condition is true.
{{else}}Condition is false.
{{/lte}}ltemust be prefaced with a pound sign (#) and conclude with a closing{{/lte}}in the block statement.
Example
In this block statement, the helper compares the
User.UserAttributes.UserAge.[0]attribute against a string17, to verify whether the user's age is equal to 17 or younger. If the response istrue, a true statement is returned. If the response isfalse, then anelsestatement is returned.{{#lte User.UserAttributes.Age.[0] "17"}}You are not old enough to rent a car.{{else}}You are old enough to rent a car.{{/lte}} -
- neq
-
Test whether two elements are not equal.
Usage
-
{{neqvalueavaluebyes='y' no='n'}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#neqvalueavalueb}}Condition is true.
{{else}}Condition is false.
{{/neq}}neqmust be prefaced with a pound sign (#) and conclude with a closing{{/neq}}in the block statement.
Example
In this block statement, the
User.UserAttributes.FavoriteColors.[0]attribute is checked against a string. If the response isRedtrue, a true statement is returned. If the response isfalse, then anelsestatement is returned.{{#neq User.UserAttributes.Favorite.Colors.[0] "red"}}You do not like red.{{else}}You like red.{{/neq}} -
- not
-
Inverts the response of a Boolean operation, so that if
notis a positive comparison, then atruestatement is returned. If the response is false, then an else statement is returned.Usage
-
{{notvalueyes='y' no='n'}}You can replace
yandnwith other values, such asyesandno, or any other string you want returned, depending on the condition. -
{{#not}}valueCondition is true.
{{else}}Condition is false.
{{/not}}notmust be prefaced with a pound sign (#) and conclude with a closing{{/not}}in the block statement.
Example
In this block statement, the
User.UerAttributes.FavoriteColors.[0]attribute is checked against a stringred, using theeqhelper. Thenothelper then returns the opposite of theeqhelper. If the response returns any color other thanred, atruea statement is returned. If the response returnsred, then anelsestatement is returned indicating a false statement.{{#not (eq User.UserAttributes.Favorite.Colors.[0] "red")}}You do not like red.{{else}}You like red.{{/not}}Example
In this example,
{{not (eq User.UserAttributes.FavoriteColors.[0] "red")}}returns false if
User.UserAttributes.FavoriteColors.[0]isred. -
- or
-
Compares whether any of the elements in the argument are equal, and then returns a response based on the result. This helper can be used for non-Boolean values.
Usage