Brevo offers two methods for showing or hiding content in your emails: using the Content visibility feature in the drag-and-drop email editor or typing if statements manually.
This article covers the manual method. If you prefer the Content visibility feature, check our dedicated article Show or hide content in your emails (Content visibility).
Use an if statement to show or hide parts of your email based on each recipient’s data. This allows you to send a single email that dynamically adapts to different contacts, depending on specific conditions.
You can define if statement conditions based on different criteria:
-
Contact attributes
Show or hide sections of your email depending on values stored in contact attributes. For example, you might show a VIP-only message to contacts with the Status attribute set as "VIP". -
Event data
Personalize content based on actions your contacts have (or haven’t) taken. For example, you could show a promotional block only to contacts who have never placed an order. -
Data feeds
Personalize content using real-time data from external feeds. For example, you can show personalized product recommendations, live pricing, or localized store information based on external data. -
Product feeds
Personalize content using using product information from your ecommerce website. For example, you can show your best seller products, or personalized product recommendations.
What is an if statement?
An if statement is a conditional rule that decides whether certain content is displayed based on a specified condition. In email templates, if statements allow you to dynamically show or hide content according to recipient data, making your emails more targeted and personalized.
For example, the emails below are sent from the same template but display different content according to recipient data:
Here are some examples:
-
Personalized greetings
Display "Hello Mr. X" for men, "Hello Mrs. Y" for women, or simply "Hello" if the name or gender is missing. -
Targeted images or promotions
Show an image of a model wearing the recipient’s preferred clothing size or feature a product in their favorite color. -
Custom promotional messages
Include special offers in transactional emails based on past purchases or other contact attributes.
Structure and syntax of an if statement
An if statement must follow specific structure and syntax rules:
- The statement begins with an if tag, followed by a condition:
{% if ... %}. - Optionally, you can include:
- Alternative conditions, which are evaluated in sequence. These begin with
{% elif ... %}. - A catch-all clause just before the end of the statement with
{% else %}.
- Alternative conditions, which are evaluated in sequence. These begin with
- Every if statement must end with
{% endif %}.
Common ways to build an if statement
Here are some common ways to build an if statement and show or hide content in your emails based on specific conditions:
if
Checks whether a value is true or an array contains elements (i.e., is not empty).
Example 1
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| Value is true or array contains elements | Value is false or array is empty |
|
Congrats! You achieved your goal this month. |
Content is hidden |
Example 2
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| Value is true or array contains elements | Value is false or array is empty |
|
The following tutors are available to help you: Abby Smith James Doe Peter Parker |
Content is hidden |
==
Checks whether an expression is true.
Example 1
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| Expression is true | Expression is false |
|
Welcome to our list! Here’s your first coupon: WELCOME25 |
Content is hidden |
Example 2
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| Expression is true | Expression is false |
|
Thank you for your support! |
Content is hidden |
if, in
Checks whether a value (substring) is present within a string or if a variable is found within an array.
Example 1
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| Value is present within a string or variable is found within an array | No value is present within a string or no variable is found within an array |
|
Thank you for your recent purchase! We hope you love your new items. |
Content is hidden |
Example 2
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| Value is present within a string or variable is found within an array | No value is present within a string or no variable is found within an array |
|
Please handle with care! One or more fragile items are in your order. |
Content is hidden |
not
Checks whether a value is false.
Example 1
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| Value is false | Value is true |
|
You are not subscribed to our secret sale alerts. Sign up here. |
Content is hidden |
and / or
Checks multiple conditions.
Example 1
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| All the conditions are true | At least one of the conditions is not true |
|
Brr. It’s cold! Here’s a coupon for 20% off of any hot beverage, today only. |
Content is hidden |
Example 2
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| All the conditions are true | At least one of the conditions is not true |
|
À l'occasion de la fête du Canada ce 1er juillet 2024, profitez de 10 % de réduction supplémentaires dans nos enseignes canadiennes ! |
Content is hidden |
Example 3
| Syntax | |
|---|---|
|
|
| Example input | |
|
|
| Example output | |
| At least one of the conditions is true | None of the conditions are true |
|
Thank you for shopping with us! Enjoy free shipping on orders over $50 in the United States and Canada. |
Content is hidden |
elif, else
Checks multiple branches.
Example 1
| Syntax | ||
|---|---|---|
|
||
| Example input | ||
|
||
| Example output | ||
| Condition1 is true | Condition2 is true | None of the conditions are true |
|
Hello Mr. Smith, |
Hello Ms. Jones, |
Hello there, |
Example 2
| Syntax | ||
|---|---|---|
|
||
| Example input | ||
|
||
| Example output | ||
| Condition1 is true | Condition2 is true | None of the conditions are true |
|
Your order is being shipped via Express Delivery! Expect it to arrive within 1-2 business days. |
Your order is on its way with Standard Shipping. It should arrive within 3-5 business days. |
Your order is being processed. We will update you with tracking details soon. |
⏭️ What's next?
- [Manual] Personalize your messages with dynamic content (Brevo Template Language)
- [Manual] Repeat a block of items in your emails using for loops
- Modify the output of a variable using filters
🤔 Have a question?
If you have a question, feel free to contact our support team by creating a ticket from your account. If you don't have an account yet, you can contact us here.
If you’re looking for help with a project using Brevo, we can match you with the right certified Brevo Agency partner.