Semplates Documentation

Find your answers below or shoot us an email.

Documentation / Template Design

/ Email Personalization - Using conditional statements

2 min read

Email Personalization - Using conditional statements

How to use conditional helpers to create more dynamic and personalized email experiences for your recipients.

What are Conditional Statements?

Conditional statements let you include or exclude content in your email templates based on certain conditions. For example, you might want to send a special offer to subscribers who have been active for more than a year.

Using if and else helpers in your html template

Handlebars provides several built-in helpers for conditional logic:

  • {{#if condition}}: Renders the block of code inside if the condition is true.
  • {{else}}: Renders the block of code if the preceding if condition is false.

Here's an example JSON structure:

{ "isPremiumUser": true, "qualifiesForDiscount": false }

In your email template, you can use these helpers as follows:

{{#if isPremiumUser}} <p>Welcome back, Premium User!</p> {{else}} <p>Welcome, please consider upgrading to our premium plan.</p> {{/if}}

Example: Conditional statements in Semplates

For this example, we will stick to the example of a fictive banking company's communication material. We want to use a conditional statement to show a discount depending on the status of the user. To do so, we might decide to add a parameter qualifiesForDiscount to the payload. For tracking purposes, we additionally want to insert a personalized discount code as a nested attribute to our user. The payload might look like this:

{ "qualifiesForDiscount": true, "user": { "firstName": "Pablo", "personalOutlink": "", "discountCode" : "annualPlanDiscount1234" }, "recommmendedArticles": [ { "heading": "Starting with ETFs", "description": "Learn how to start with index funds today. Read our guide to up your ETF game", "outlink": "" }, { "heading": "The power of compounding interests", "description": "Why time is the most powerful force in saving for retirement. See this comparison…", "outlink": "" }, { "heading": "Maximizing Tax Efficiency", "description": "Discover strategies to minimize your tax burden while investing. Get the insights now.", "outlink": "" } ] }

Now we can head over to Semplates' Template Editor and start customizing our template. We use html blocks to hold the Handlebars Syntax and add the content that should be displayed when a customer is eligible for the discount:

Screenshot of Semplates' template editor showcasing the use of conditional variables

AS you can see the template also contains blog content that we would like to show in case we do not want to show the promotion block. Now, when opening the Template Preview, you can add placeholders on the right site of the screen and review the rendered template on the left:

Screenshot of Semplates' template preview that showcases the use of conditionals (true case)

As you can see, conditional placeholders are rendered as a switch, which makes it super easy to turn them on and off to test how the template renders:

Screenshot of Semplates' template preview that showcases the use of conditionals (false case)

Make sure to test your placeholders thoroughly to ensure that they behave as expected. Incorrectly set conditions could lead to irrelevant or confusing messages.

Important Notes

Pro Tip: Switch to the Expert Mode (available on Premium plans and above), to edit the expected JSON structure directly. This view is especially valuable, when working with complex or large placeholder payloads, and, when aligning your SES API calls to your template designs.

With this guide, you're now ready to use basic conditional statements in your Semplates email templates. We also explore other advanced personalization features like nested attributes and iterating through lists.


Our cookie policy

We use cookie technology to analyse the website traffic and page usage, improve the navigation experience and support our marketing efforts. If you accept, you grant us permission to store cookies on your device for those purposes only.
Please read our Data Privacy Policy for more information.

Accept all

Only necessary