Skip to main content

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.

Template
Variables (JSON)
Preview
Hello John

Insert content when people are CC'd

Template
Variables (JSON)
Preview
I've CC'd everyone here.

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.

Template
Variables (JSON)
Preview
Here's the email. Forgot to CC anyone.

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

Template
Variables (JSON)
Preview
John

Insert first or last name if available

Template
Variables (JSON)
Preview
Briskine

Insert a default if first name is not available

Template
Variables (JSON)
Preview
Hi there

Insert full name only if both first name and last name are available

Template
Variables (JSON)
Preview
Hello John Briskine

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

Template
Variables (JSON)
Preview
Hello John from Briskine

Check if email is not equal

Template
Variables (JSON)
Preview
Is email different from john@briskine.com? true

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.

Conditional good morning / afternoon / evening

Template
Preview
Good afternoon