Variables and dynamic content

Conditionally show or hide email blocks using if statements

Show or hide a block for some recipients, with your platform’s if statements.

4 min readUpdated

Tabular’s condition option can be used to conditionally show or hide email blocks based on personal client data. In the condition option settings you specify the opening and closing markup for if statements.

What are if statements?

You can include conditional logic in your email templates by using if statements or unless statements. To be able to use if statements, your email service provider should offer a templating language with if statement support.

The idea is that the block that you wish to conditionally show or hide should be wrapped in an if statement. Wrapping a block, means that before the block we add an opening expression, and after the block we add a closing expression.

In the opening expression of the if statement you add a condition, and only if the condition evaluates to true, the block will be visible.

The templating language used differs per email service provider, but for example the HTML when using the Handlebars templating language, would look like the following:

HTML
{{#if isMember}}
<h1>{{firstName}} {{lastName}}</h1>
{{/if}}

When you have the following client data:

JavaScript
{
  isMember: true,
  firstName: "Yehuda",
  lastName: "Katz",
}

Would resolve to the following HTML, when the email service provider substitutes the if statement and the variables with the provided values:

HTML
<h1>Yehuda Katz</h1>

Wrapping a Tabular block in an if statement

  1. From the Layers menu, select the block that you wish to wrap in an if statement.
  2. In the Styling menu, click on the button for adding the condition block setting. This button can be identified by the icon illustrating a switch.
  3. After clicking on the show/hide block button the condition item will be added to the Dynamic content settings. Click on this condition item to open a popover where you will input the if statement synax.
  4. You will find two input fields:
    1. in the first input, add the opening expression of the if statement. For example, for HubSpot’s HubL language this would look like: {% if condition %}, where condition should be replaced with the boolean rule that will be evaluated as being true or false. With the Handlebars language it would look like: {{#if condition}}.
    2. in the second input, add the closing expression of the if statement. For example for HubSpot’s HubL language this would look like: {% endif %}. With the Handlebars language it would look like: {{/if}}.

Using HubSpot’s HubL language, in Tabular this would then look like:

Example of using HubSpot’s HubL language if statement on a Tabular email block.

Using the Handlebars templating language, in Tabular this would then look like:

Example of using Handlebars’ if statement on a Tabular email block.

Substituting if statement variables with client data

Each uniquely personalized email will need to be automatically generated and during this the if-else variables will be substituted with client data.

This process of substituting the variables with the client data is typically performed by your email service provider (ESP). Your ESP should then also have access to that client data.

Some ESPs may offer functionalities to manually add the client data or they might collect the client data. Other ESPs may offer integrations, so that you can connect the database where you’ve stored the client data, with the ESP, so that the ESP can fetch the client data from your database. If you programmatically send emails using the ESP’s API, most API’s offer endpoints that you can use to send variable values to the ESP.

Another option if you have developers in your team, is to do this process of substitution on your own backend server, and then sending the HTML using the API of an ESP.

Email Service Providers that support the if statement

Most email service providers offer a templating language, see the following table that lists the most commonly used ESPs and if they offer if-else support:

Email service provider Link to documentation If statement support
HubSpot HubL Templating Language ✅ HubSpot If statement
Mailchimp Merge tags ✅ Conditional merge tags
Mailchimp Transactional Handlebars and Merge Tags ✅ The if helper
Postmark Mustachio ✅ Scoping
Crisp Handlebars ✅ #if
Mailgun Handlebars ✅ #if
Brevo Handlebars ✅ #if
Klaviyo Conditional logic ✅ #if
SendGrid Using Handlebars ✅ #if
MailerLite Variables in MailerLite ❓ No documentation
Mailjet Mailjet Templating Language ✅ If-conditional statements
Auth0 Using Liquid Syntax ✅ If-else
Moosend ❌ No support ❌ No support
VBOUT ❓ No documentation ❓ No documentation
ZeptoMail Dynamic Templates) ✅ Conditional statement
SendPulse Clever personalization ✅ Examples
Acumbamail ❓ No documentation ❓ No documentation
Sendy ❓ No documentation ❓ No documentation
Transpond Merge Tags ✅ Conditional merge tags
Encharge Personalization with Liquid ✅ If-else
Was this article helpful?

Still stuck? Write to Email us