Conditional Helpers
You can use conditional/logic helpers to insert different content depending on certain conditions.
If/Else
The if/else
block helper conditionally renders blocks of content. if
and else if
statements render content when the condition is true, and else
renders content when all previous conditions are false.
Here are some examples of how you can use it.
Insert first name when available
When to.first_name
is available, the template will render Hello John
. If to.first_name
is not available, the template will render Hello there
.
Change the template variables to see it works.
Insert content when people are CC'd
Unless
The unless
helper is the inverse of the if
helper. It will render when the condition is false.
Insert content when people are not CC'd
Rename the to
variable in the JSON
tab to cc
, to see how it renders differently.
And/Or
The and/or
helpers allow to string together complex conditions for rendering.
You can use the and
helper by itself to render the last true value, if all values are true. The or
helper, used by itself, will render the first true value, if at least one value is true.
Both of them can be combined with the if
helper, as subexpressions, to check for multiple values.
Insert first name if last name is available
Insert first or last name if available
Insert a default if first name is not available
Insert full name only if both first name and last name are available
Equal/Not Equal
The compare
helper lets you check if two, or more, values are equal or not. The helper requires at least three parameters: the operator (can be one of ===
, ==
, !==
, !=
, <
, <=
, >
, >=
), and at least two values. You can also add more values if you want to compare three or more.
Like the and/or
helpers, you can combine the compare
helper with the if
block helper to conditionally render different blocks of content.
Insert different content for a specific email
Check if email is not equal
Greater than and Less than
The compare
helper can also be used to check if a value is greater, or less, than another, by using the <
, <=
, >
, >=
, operators.