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. You can use these same conditions for each show/hide logic variant. 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

You can use conditions in:

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.

If you use logic variants, add a fallback so that recipients who don’t match any variant, including those without the property, still see content.

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. The same structures apply to the condition for each logic variant.

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

Any

not person|lookup:'Favorite Color'

The Favorite Color property is missing or empty, or its value is numeric 0 or the boolean False

Any

person|lookup:'Favorite Color' == 'green'

The Favorite Color property has the value green

Text, Number

person|lookup:'Favorite Color' != 'green'

The Favorite Color property does not have the value green

Text, Number

person|lookup:'Age' > 20

The Age property contains a number greater than 20

Number

person|lookup:'Age' >= 20

The Age property contains a number greater than or equal to 20

Number

person|lookup:'Age' < 20

The Age property contains a number less than 20

Number

person|lookup:'Age' <= 20

The Age property contains a number less than or equal to 20

Number

'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

List, 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

List, 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

The VIP property is set to the boolean value true

person|lookup:'VIP' == 0

The VIP property is set to the boolean value false

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|lookup:'VIP' == 'true' or person|lookup:'VIP' == 'True'

The VIP property is set to the boolean value true or the strings true or True

person|lookup:'VIP' == 0 or person|lookup:'VIP' == 'false' or person|lookup:'VIP' == 'False'

The VIP property is set to the boolean value false or the strings false or False

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

Conditions across logic variants

When a block or section has show/hide logic variants, each variant has its own condition. Variants are checked from top to bottom, and each recipient sees only the first variant they match. Because of this, a later variant’s condition doesn’t need to exclude audiences that an earlier variant already covers.

For example, a block could have these 2 variants:

  1. Variant 1: person|lookup:'VIP' == 1
  2. Variant 2: person|lookup:'Favorite Color' == 'green'

A VIP whose favorite color is green sees only Variant 1. To show them Variant 2 instead, drag Variant 2 above Variant 1 or make Variant 1’s condition more specific.

To show content to everyone who doesn’t match a variant, add a fallback instead of writing a catch-all condition such as person|lookup:'Favorite Color' != 'green' and person|lookup:'VIP' != 1. The fallback doesn’t have a condition and also covers recipients who don’t have the property set.

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:

  1. Double-click the text block.
  2. 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.
  3. Click the logic block’s Edit pencil to open Edit logic block.
  4. 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.

  1. Navigate to Content > Templates and select Email: saved.
  2. Open the HTML template’s 3-dot menu and select Clone to drag and drop.
  3. 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

Was this article helpful?
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