This article explains how to use Twig code to control content across sections in your email templates and selectively show or hide it for specific guests.
OVERVIEW
With Twig, you can dynamically control content in your email template—even across the boundaries of individual sections. For example, you can display certain areas only to selected guests based on their contact details.
The principle: You open a Twig condition in one HTML section, place any content in between, and close the condition in another HTML section.
REQUIREMENTS
Before you start, you need:
- Access to your event’s Email Template Editor
HOW IT WORKS
The control is done in three parts:
| Part | Section | Function |
| 1 | First HTML section | Open Twig condition, e.g. {% if contact.first_name == 'Roberto' %} |
| 2 | Any section in between | Content shown only if the condition is met |
| 3 | Second HTML section | Close condition with {% endif %} |
STEP-BY-STEP GUIDE
Example: Display a section only for a specific person.
STEP 1:
PREPARE HTML SECTIONS
Insert two HTML sections into your email template. The first section contains the Twig condition; the second closes it. All desired content is placed in between.
STEP 2:
INSERT CONDITION IN THE FIRST HTML SECTION
In the first HTML section, insert the Twig condition.
In this example, only guests with the first name Roberto will see the following content:
| {% if contact.first_name == 'Roberto' %} |
STEP 3:
INSERT CONTENT BETWEEN THE SECTIONS
Place all desired content (text, buttons, images, etc.) between the two HTML sections. This content will only be displayed if the condition is met.
STEP 4:
CLOSE CONDITION IN THE SECOND HTML SECTION
In the second HTML section, close the condition:
| {% endif %} |
| Tip: Make sure the background color of your HTML rows matches the rest of the email to ensure a visually consistent overall appearance. |
MORE EXAMPLES
Display content based on company name
{% if contact.company == 'AirLST' %} {# Content only for AirLST employees #} {% endif %} |
Display content based on country selection
{% if contact.country == 'Belgium' %} {# Content only for guests from Belgium #} {% endif %} |
FREQUENTLY ASKED QUESTIONS
Can I nest multiple conditions?
Yes, you can {% if %} blocks inside each other or combine them with and / or .
What happens if the condition is not met?
The content between the two HTML sections will not be displayed for that guest.
The rest of the email template remains unchanged.
Can I also use else branches?
Yes, use {% else %} or {% elseif %} in the same HTML section or in a separate section between the opening and the {% endif %}.
Does this also work with custom fields?
Yes, custom fields can be used in conditions.