The drag-and-drop template builder allows you to use contacts' profile properties and event variables to control who sees a given block in a single email template. If you click the ? mark in the block editor for a given block, you can configure the block to show only when certain a profile property is true for the recipient. You can also create a condition around an event variable if your email is triggered by a flow.
After clicking this ? icon, you will be prompted to set a condition that determines whether or not the block is shown. Make sure to then toggle the On button to enable this feature.
Show or Hide a Block Based On a Profile Property
Profile variables can be found in a contact's profile when you go to the Profiles tab. For Klaviyo-specific variables, the format is always person.[Property Name]. In the example below, this block will only appear for recipients who live in Canada.
Logical operators that can be used here:
- Show block if property equals A: person.Country = "A"
- Show block if property doesn't equal A: person.Country != "A"
- Show block if property isn't set: not person.Country
- Show block if property doesn't equal A or B: person.Country != "A" and person.Country != "B"
- Show block if property is set: person.Country
You can use "or" statements to target people who have inputted one custom property or another. For example, you may want to target people who live in Boston OR Providence:
- Show block if property equals Boston or Providence: person.City = "Boston" or person.City = "Providence"
However, please note that if you want to target people who do NOT live in Boston or Providence, you would use the following logic:
- Show block if property doesn't equal Boston or Providence: person.City != "Boston" and person.City != "Providence"
This is because you want to capture people who do not live in Boston AND people who do not live in Providence.
Show or Hide a Block Based on an Event Variable
If you are building an email template within a flow, you can also formulate a condition around an event variable. Let's say, for an abandoned cart email, you would only like to show a certain block when someone's cart contained more than one item. First, find the event variable that corresponds with what you are looking to target.
The variable we want to target in this example is Item Count:
We then need to configure a short condition statement that tells the block to only show if Item Count is greater than 1.
The event variable we're going to use, copied from the preview window, is event|lookup:'Item Count'.
The condition statement we need to create is: event|lookup:'Item Count' > 1
Now this template block will only show to a recipient if the condition statement evaluates to True.
You can also show or hide blocks based on if one value is in a list of other values. For example, if a certain collection was purchased from in an order (i.e. if Collection X is part of the Collections array in a Placed Order event) or whether a certain item was part of an order (i.e. if Item X is part of the Items array in a Placed Order event):
- Show block if X property is part of Y list: "Dog Treats" in event.Collections
- Show block if X property is not part of Y list: not "Dog Treats" in event.Collections
- Show block if X property is part of Y list: "Gold Sneakers" in event.Items
- Show block if X property is not part of Y list: not "Gold Sneakers" in event.Items
Show or Hide a Block Based on a Custom Property
Custom properties are stored on a contact's profile under the Custom Properties section. The filter you will use will always be: person|lookup:'[Custom Property]' = '[X]'
To follow this example, you will have to have gender information stored as a custom property for your contacts. You can start collecting gender, or any type of information, from your customers and subscribers by asking in sign up forms or within emails.
Here is the logic you would use for each block to achieve the following:
- Show if Gender is set as female: person|lookup:'Gender' = 'female'
- Show if Gender is set as male: person|lookup:'Gender' = 'male'
- Show if Gender is not set: not person.Gender
- Show if Gender is not set as male or female: person|lookup:'Gender' != 'male' and person|lookup:'Gender' != 'female'
- Show if Gender is set: person.Gender
You can use "or" statements to target people who have inputted one custom property or another. For example, you might want to ensure that you capture different possible spellings of a word when you are targeting subscribers who have described their gender as "male" OR "Male." To do this, you would use the following syntax:
- Show if Gender is set as male or Male: person|lookup:'Gender' = 'male' or person|lookup:'Gender' = 'Male'