You can use conditional logic helpers to display (or not display) content depending on whether certain conditions are met.
# In this article
- Display a fallback value if a field is empty
- Display content if text is found within a string
- Display content if the value of a field is true
- Display content if the values of multiple fields are true
- Display content if the value of any of several fields is true
- Display content if the value of a field is false
- Display content unless the value of a field is true
- Display content if one number is equal to another
- Display content if a value is greater than another
- Display content if a number is greater than or equal to another number
- Display content if one value is less than another
- Display content if a value is less than or equal to another
- Display content if the remainder of an equation is a certain value
- Display content if two strings match
- Want to learn more?
# Display a fallback value if a field is empty
The defaultIfEmpty helper checks whether a field is undefined or empty, then
displays a specified fallback value if it is.
# Properties
fieldName — The name of the user or event field that you want to check.
fallbackContent — The content you want to display if fieldName is empty or
missing on a user's profile.
# Format
# Example
| Code | Example firstName value | Output |
|---|---|---|
| Hi there |
# Display content if text is found within a string
The #ifContainsStr block helper searches a string for a substring and if the
substring is found, renders the block's content.
NOTE
If a merge tag using the #ifContainsStr helper references an empty or missing
field, the template fails, and the message will not be sent to that user.
# Properties
string — The name of the field containing the string you want to search.
substring — The name of the substring you want to search for within the first
string.
content — The content that should be displayed if the substring is found within
the first string.
# Format
# Example
| Code | Example favoriteFoods value | Output |
|---|---|---|
| blueberry scone | It's blueberry season! |
# Display content if the value of a field is true
The if helper checks to see if the value of a field is true. If it is, the
helper displays the contents of the block. If the value of the field is false,
the helper displays either nothing or, if an else block is included, some
alternative content.
# Properties
fieldName — The name of the field whose true/false value you want to check.
content — The content that should be displayed if the value of fieldName is
true.
(Optional) alternateContent — The content that should be displayed if the value
of fieldName is false.
# Format
# Example
| Code | Example activeUser value | Output |
|---|---|---|
| false | We miss you! |
# Display content if the values of multiple fields are true
The and helper checks to see if the values of multiple fields are true. If
they are, the helper displays the contents of the block. If one or more values
of the fields is false, the helper displays either nothing or, if an else
block is included, some alternative content.
# Properties
fieldName1 — The name of the first field whose true/false value you want
to check.
fieldName2 — The name of the second field whose true/false value you want
to check.
... — The names of the third, fourth, fifth (etc.) fields whose true/false
values you want to check. (You can add as many fields as you like.)
content — The content Iterable should display if the values of all the fields
are true.
alternateContent (optional) — The content Iterable should display if the value
of any of the fields is false.
# Format
# Example
| Code | Example optedIn value | Example completedSurvey value | Output |
|---|---|---|---|
| true | true | Thanks for completing the survey! Your feedback is so valuable to us. |
# Display content if the value of any of several fields is true
The or helper checks multiple fields to see if any of the values are true.
If at least one is, it displays the associated block of content. If none of the
fields has a value of true, it displays the alternate content associated with
else.
# Properties
fieldName1 — The name of the first field whose true/false value you want
to check.
fieldName2 — The name of the second field whose true/false value you want
to check.
... — The names of the third, fourth, fifth (etc.) fields whose true/false
values you want to check. (You can add as many fields as you like.)
content — The content Iterable should display if the value of any of the
specified fields is true.
alternateContent — The content Iterable should display if the values of all
the specified fields are false.
# Format
Standard helper:
Block helper:
# Example
| Code | Example likesCoffee value | Example likesTea value | Output |
|---|---|---|---|
| true | false | Craving a hot drink? |
# Display content if the value of a field is false
The not helper checks to see if the value of a field is false. If it is, it
displays the block's content. If the value of the field is true, the block
displays the alternate content associated with else.
# Properties
fieldName — The name of the field whose true/false value you want to check.
content — The content Iterable should display if the value of the specified
field is false.
alternateContent — The content Iterable should display if the value of the
specified field is true.
# Format
Standard helper:
Block helper:
# Example
| Code | Example age value | Output |
|---|---|---|
| 17 | Sorry, this sweepstakes is only open to adults 18 and over. |
# Display content unless the value of a field is true
The unless helper checks to see if the value of a field is true. If it is,
the helper displays the contents of the block. If the value of the field is false,
the helper displays the alternative content associated with else.
# Properties
fieldName — The name of the field whose true/false value you want to check.
content — The content Iterable should display if the value of fieldName is
true.
# Format
# Example
| Code | Example activeUser value | Output |
|---|---|---|
| false | We miss you! Come back for 10% off. |
# Display content if one number is equal to another
The #ifEq helper checks whether one value (numerical or text) is equal to
another value. If the two values are equal, the associated content is displayed.
If the values are not equal, the helper displays either nothing or, if an
else block is included, some alternate content.
You can use #ifEq to compare values represented as strings, longs, and doubles.
(The values don't need to be the same data type.)
# Properties
fieldName1 — The name of the first user or event data field whose value you
want to compare.
fieldName2 — The name of the second user or event data field whose value you
want to compare.
content — The content that should be displayed if the two values are equal.
alternateContent (optional) — The content that should be displayed if the two
values are not equal.
# Format
# Example
| Code | Example firstName value | Example preferredName value | Output |
|---|---|---|---|
| Elizabeth | Ellie | Hi, Ellie! |
# Display content if a value is greater than another
The #ifGt checks whether one value is greater than another value. If the first
values is greater than the second value, the associated content is displayed. If
the first value is less than the second value (or the two values are equal),the
helper displays either nothing or, if an else block is included, some
alternate content.
You can use #ifGt to compare values represented as strings, longs, and doubles.
(The values don't need to be the same data type.)
# Properties
fieldName1 — The name of the first user or event data field whose value you
want to compare.
fieldName2 — The name of the second user or event data field whose value you
want to compare. (Alternatively, you can include a literal value here.)
content — The content that should be displayed if the value of fieldName1 is
greater than fieldName2.
alternateContent — The content that should be displayed if the value of
fieldName1 is less than fieldName2.
# Format
# Example
| Code | Example loyaltyPoints value | Output |
|---|---|---|
| 105 | You've reached VIP status! |
# Display content if a number is greater than or equal to another number
The #ifGte helper compares two numbers to see if the first number is greater
than or equal to the second number. If it is, the helper displays the contents
of the block. If the first number is less than the second number, it displays
the alternate content associated with else.
You can use #ifGte to compare values represented as strings, longs, or doubles.
(Values don't need to be the same data type.)
# Properties
fieldName1 — The name of the field whose value you want to compare to #.
fieldName2 — The name of the second field whose value you want to compare.
(Alternatively, you could enter a literal numerical value here.)
content — The content that should be displayed if the value of fieldName1 is
greater than or equal to fieldName2.
alternateContent — The content that should be displayed if the value of
fieldName1 is less than fieldName2.
# Format
# Example
| Code | Example age value | Output |
|---|---|---|
| 21 | Check out our new French wines! |
# Display content if one value is less than another
The #ifLt helper checks whether one number is less than another number.
If "true", the block displays some content. If "false", no content is displayed.
(Optionally, you can include an else block in order to display some content if
the expression is "false".)
You can use #ifLt to compare values represented as strings, longs, and doubles.
(The values don't need to be the same data type.)
# Properties
fieldName1 — The name of the first field whose value you want to compare.
fieldName2 — The name of the second field whose value you want to compare.
(Alternatively, you could enter a literal numerical value here.)
content — The content that should be displayed if the value of fieldName1 is
less than to fieldName2.
alternateContent — The content that should be displayed if the value of
fieldName1 is not less than fieldName2.
# Format
# Example
| Code | Example purchases value | Output |
|---|---|---|
| 2 | Keep shopping to reach VIP status. |
# Display content if a value is less than or equal to another
The #ifLte helper compares two numbers to see if the first number is less than
or equal to the second number. If it is, the helper displays the contents of the
block. If the first number is greater than the second number, it displays the
alternate content associated with else.
You can use #ifLte to compare values represented as strings, longs, and doubles.
(The values don't need to be the same data type.)
# Properties
fieldName1 — The name of the first field whose value you want to compare.
fieldName2 — The name of the second field whose value you want to compare.
(Alternatively, you could enter a literal numerical value here.)
content — The content that should be displayed if the value of fieldName1 is
less than or equal to fieldName2.
alternateContent — The content that should be displayed if the value of
fieldName1 is not less than or equal to fieldName2.
# Format
# Example
| Code | Example age value | Output |
|---|---|---|
| 17 | Check out this summer's coolest kids' movies! |
# Display content if the remainder of an equation is a certain value
The #ifModEq helper displays a block of content if the remainder of an equation
is equal to a certain value.
# Properties
fieldName — The name of the field whose value you want to divide by divisor.
divisor — The field containing the value you want to divide fieldName by.
(Alternatively, you could enter a literal numerical value here.)
# — The remainder value you wish to check for.
content — The content that should be displayed if the remainder of fieldName
divided by divisor is equal to #.
# Format
# Example
| Code | Example daysSinceLastSend value | Output |
|---|---|---|
| 60 | New month, new featured recipe! |
# Display content if two strings match
The #ifMatchesRegexStr helper can be used to compare strings in two ways:
- Check whether a string exactly matches another string
- Check whether one string contains another string
If an ifMatchesRegexStr statement evaluates to "true," the helper displays the
block's content. If the statement evaluates to "false," the helper either
displays nothing or, if an else statement is included, displays the provided
alternate content.
# Properties
fieldName — The name of the field whose value you want to compare to another
string.
regEx — The regular expression
you want to use to search for a match between the two strings.
content — The content you want to display if the ifMatchesRegexStr statement
evaluates to "true."
# Format
# Example
| Code | Example dogName value | Output |
|---|---|---|
| pippin | Is your dog's name Pippin? |
NOTE
Regular expression queries are case-sensitive, which is why this example uses
[Pp] to search for both the uppercase and lowercase versions of the name
"Pippin."
# Want to learn more?
For more information about some of the topics in this article, check out these resources. Iterable Academy is open to everyone — you don't need to be an Iterable customer!
Iterable Academy
- Handlebars 101
- Intermediate Handlebars
- A Moment with Support: Using Handlebars to Generate Random Numbers
- Advanced Handlebars
Support docs