Conditional logic reference for templates
Estimated 4 minute read
|
Updated Feb 3, 2026, 12:00 AM EST
Table of contents
- You will learn
- Where you can use conditions
- Tips for success
- Condition structures
- Build complex conditions
- Use conditions in a converted HTML template
- Additional resources
You will learn
Learn about all the available conditions you can use to dynamically display a block, section, or custom-coded piece of content only to certain recipients. To learn how to use these conditions in your templates, head to our article on how to show or hide template blocks based on dynamic variables.
Learn how to use conditional logic:
- Where you can use conditions
- Tips for success
- Condition structures
- Build complex conditions
- Use conditions in a converted HTML template
Where you can use conditions
You can use conditions in:
- Emails
- Create show/hide logic to dynamically display blocks or sections only to certain people.
- If you prefer not to write code, use the show/hide logic builder instead.
- Write if/else conditionals to create custom Django statements.
- Customer Hub
- Write if/else conditionals to create custom Django statements in content blocks
Tips for success
When building out show/hide conditions, pay attention to the details. Show/hide conditions are case-sensitive, and spelling must exactly match your profile or event data.
Also, make sure to consider all possible viewers. For example, if you show a specific block only to residents of a certain state, cover all possible spellings of that state name (e.g., Massachusetts, massachusetts, mass, MA). Also take into consideration profiles who may not have the property set at all.
Once you’ve built the message and applied your conditions, preview using a variety of profiles to confirm that the message displays as you intended for all scenarios.
Condition structures
Conditions should include 1-3 elements, depending on your goal for the block and the data you’re using. The condition must at least include a variable (e.g., person|lookup:'Favorite Color'). It may also include a comparison function, like == (equals) or > (greater than) and a value, which specifies a property value to look for. Additionally, certain conditions begin with not, if you’d like the block to only appear for profiles that do not meet a condition.
For custom-coded show/hide logic, enter the expression by itself, without {{ }} or {% if ... %} tags. Add spaces on both sides of comparison operators. Use straight quotes around text values, such as 'green', and leave numbers unquoted, such as 20.
The chart below contains a complete list of possible structures a show/hide condition can follow.
| Sample condition | Show the block if... | Acceptable data types |
| person | lookup:'Favorite Color' | The Favorite Color property has a value that is not empty, numeric 0, or the boolean False |
| not person | lookup:'Favorite Color' | The Favorite Color property is missing or empty, or its value is numeric 0 or the boolean False |
| person | lookup:'Favorite Color' == 'green' | The Favorite Color property has the value green |
| person | lookup:'Favorite Color' != 'green' | The Favorite Color property does not have the value green |
| person | lookup:'Age' > 20 | The Age property contains a number greater than 20 |
| person | lookup:'Age' >= 20 | The Age property contains a number greater than or equal to 20 |
| person | lookup:'Age' < 20 | The Age property contains a number less than 20 |
| person | lookup:'Age' <= 20 | The Age property contains a number less than or equal to 20 |
| 'green' in person | lookup:'Favorite Colors' | The property Favorite Colors contains a list, and green is one of the list items, OR The property Favorite Colors contains text, and green exists anywhere in the text |
| not 'green' in person | lookup:'Favorite Colors' | The property Favorite Colors contains a list, and green is not one of the list items, OR The property Favorite Colors contains text, and green does not exist anywhere in the text |
Conditions for booleans
If you are referencing data stored as a boolean, you’ll need to use 1 and 0 rather than “true” and “false” in your show/hide condition definition. Do not surround the 1 or 0 in quotes. Use the sample conditions below as a template.
| Sample condition | Show the block if... |
| person | lookup:'VIP' == 1 |
| person | lookup:'VIP' == 0 |
Conditions for booleans stored as text
If your true/false data is stored as text, not as a boolean, use the sample conditions for text properties above. If you aren’t sure, or if you are referencing a property that contains both booleans and text, you can use these structures to cover all scenarios. Include all spellings and capitalizations that are present in your data.
| Sample condition | Show the block if... |
| person | lookup:'VIP' == 1 or person |
| person | lookup:'VIP' == 0 or person |
Build complex conditions
If you would like your block to display to people who meet multiple criteria, or if you have a complex use case, you can use multiple show/hide conditions for one block. To do so, connect the conditions with lowercase and or or. Use and when both conditions must be true, and or when either can be true. When you combine them, and is evaluated before or. For example, if you want to display a block to anyone in Massachusetts, but Massachusetts is spelled differently on some profiles, you can use a condition like this:
person.location.region == 'Massachusetts' or person.location.region == 'massachusetts' or person.location.region == 'mass' or person.location.region == 'MA'
If you only want to show a block to people whose favorite color is green, and who are also VIPs, you can use a condition like this:
person|lookup:'Favorite Color' == 'green' and person|lookup:'VIP' == 1
Conditional statements and the inline text editor
Supported Django statements in text blocks appear as logic blocks in the inline text editor. Their tags remain part of the template. To edit a condition:
- Double-click the text block.
- If This block uses unsupported formatting appears, review the formatting options. Select Edit in updated text block to continue with adjusted styling. To keep the existing formatting, select Convert to HTML block and edit the code in the Content tab instead of following the remaining steps.
- Click the logic block’s Edit pencil to open Edit logic block.
- Update the condition and click Save. Click outside the text block to finish editing.
You can also edit Django statements directly in an HTML block’s Content tab.
The following tags are represented in logic blocks:
- {% for ... %}
- {% endfor %}
- {% if ... %}
- {% elif ... %}
- {% else %}
- {% endif %}
- {% with ... %}
- {% endwith %}
Use conditions in a converted HTML template
To use the drag-and-drop editor with a saved HTML template, create a converted copy. You need permission to edit templates. The original HTML template stays unchanged.
- Navigate to Content > Templates and select Email: saved.
- Open the HTML template’s 3-dot menu and select Clone to drag and drop.
- Select Converted templates. When the copy’s status is Ready to use, click its name to open it in the editor.
Review the copy’s conditional content and make any needed edits. Click Preview and check profiles that meet your conditions, profiles that do not, and profiles without the referenced property before using the template.
Additional resources
Learn how to show a particular block or section in an email to certain recipients using the template editor’s show/hide logic builder. - Message personalization reference
Learn how to use Klaviyo’s personalization variables, or tags, to customize the experience for your customers. - Understanding profiles in Klaviyo
Learn about profiles, including how to find them and the data available on the profile page. Profiles are used to keep track of all the information you have about your customers and prospects. - Glossary of variable filters
Was this article helpful?
YesNo
Use this form only for article feedback. Learn how to contact support.
Explore more from Klaviyo
Community
Connect with peers, partners, and Klaviyo experts to find inspiration, share insights, and get answers to all of your questions.
Partners
Hire a Klaviyo-certified expert to help you with a specific task, or for ongoing marketing management.
Support
Access support through your account.
Email support (free trial and paid accounts) Available 24/7
Chat/virtual assistance Availability varies by location and plan type
