How to add conditional logic to email templates using the logic builder
You will learn
Learn how to use the logic builder to add dynamic conditional logic—like if/else statements and for loops—directly to text blocks in your email templates. This allows you to display personalized content to different recipients based on their profile or custom properties, without writing code.
Before you begin
The logic builder is available in:
- Drag and drop email editor — text blocks, table blocks, and split blocks
- Text only email editor — via a modal instead of a side panel
To use the logic builder, you'll need at least one profile in your account that has the property you want to evaluate. Profile and custom properties can be added through sign-up forms, CSV uploads, ecommerce integrations, and other list growth tools.
Note: The logic builder supports profile and custom properties. It does not support event data. To use event data in your logic, use the Convert to code option and write Django tags directly.
Add an if/else statement
Use an if/else statement to display different content to recipients based on a profile or custom property. For example, you might show a VIP discount block only to customers with more than 500 loyalty points, and a sign-up incentive to everyone else.
In the drag and drop editor
- Double-click into a text block, table block, or split block to enter editing mode.
- Click the Insert button in the toolbar at the top of the page.
- Select If/else from the dropdown menu.
- A side panel will open on the left, and the canvas will shift to the right.
- Configure your if statement:
- Use the first dropdown to choose a profile or custom property to evaluate.
- Use the second dropdown to select an operator (e.g., equals, is greater than, is set).
- Enter or select a value to compare against, depending on the operator chosen.
- Optionally, click Add condition to add additional criteria to the if statement.
- Use AND or OR to connect conditions. OR is selected by default.
- Click the clone button on a condition to duplicate it as a new OR condition.
- To add an else if branch, click Add else if and configure the conditions the same way. Recipients who meet these conditions—but not the if statement—will see this content.
- To add an else branch, check the Else checkbox (checked by default). Edit the content in the canvas to define what recipients who don't meet any condition will see. Uncheck the box to remove the else branch entirely.
- Edit the content in the canvas for each condition. Each condition appears as a blue box while being configured.
- When finished, click the back arrow to close the panel and save your logic.
Tip: To remove all configured logic from a block, click Remove logic in the side panel.
Note: Clicking Delete on the initial if statement will reset its values rather than remove the statement entirely. Clicking Delete on an else if or else branch will remove that branch.
In the text only editor
Follow the same steps above, but select Insert from the text editing toolbar. The logic builder will open in a modal instead of a side panel. All the same configuration options are available.
Add a for loop
Use a for loop to iterate through a list of items and display repeated content for each one. For example, you might loop through a customer's recently viewed products to show each one in the email.
In the drag and drop editor
- Double-click into a text block, table block, or split block.
- Click the Insert button in the toolbar.
- Select For loop from the dropdown menu.
- A side panel will open on the left.
- In the Variable field, enter the list you want to loop through (e.g., event.items).
- In the Item alias field, enter a name to reference each individual item within the loop (e.g., item).
- Edit the content in the canvas to define what will be displayed for each item.
- Click the back arrow to close the panel and save your logic.
Tip: To remove the loop entirely, click Remove logic in the side panel.
Add a configurable tag
Use a configurable tag to insert Django tags that aren't covered by the if/else or for loop builders—such as with statements or catalog tags.
- Double-click into a text block, table block, or split block.
- Click the Insert button in the toolbar.
- Select Configurable tag from the dropdown menu.
- A side panel will open on the left.
- In the Tag name field, enter the tag that will open and close the block (e.g., with).
- In the Code text area, add your custom Django tag code.
- To add a branch, click Add branch. This creates an additional section where you can configure another tag name and code block.
- Click the back arrow to close the panel and save your logic.
Work with nested logic
You can nest logic statements inside each other—for example, an if/else statement inside a for loop. This allows you to build highly targeted content sequences.
When logic is nested:
- Vertical line icons indicate the nesting level of each logic statement.
- Hovering over a parent statement highlights the full nested block.
- Hovering over a child statement highlights only that child.
- You can collapse and expand child statements independently from the parent.
- If more than three levels of logic are nested, a +[number] indicator appears to show the additional nesting depth.
Convert logic to code
If you need more control over your logic, or want to use unsupported features like event data or date comparisons, you can convert your logic builder configuration to raw Django code.
Warning: Converting logic to code is a one-way action and cannot be undone. You will not be able to switch back to the logic builder after converting.
To convert:
- Open the logic builder side panel for the block you want to update.
- For if/else statements, each individual segment (if, else if) has its own Convert to code button. Click the one for the segment you want to convert.
- For for loops, click the single Convert to code button for the entire loop.
- A warning modal will appear. Confirm that you want to proceed.
- After conversion, the converted code will appear in a code editor in the side panel. You can edit it directly from there.
This converted state is permanent—it will persist even after you close the panel or navigate away from the template.
Differences in the text only editor
The logic builder in the text only editor works the same as in the drag and drop editor, with one key difference: logic is configured in a modal rather than a side panel. All the same options for if/else, for loops, configurable tags, nesting, and converting to code are available.
After logic is configured, it appears in the canvas the same way as in the drag and drop editor. Clicking Edit on a configured condition opens the modal to allow further edits.