How to Show or Hide Template Blocks Based on Dynamic Variables

read
Last updated at:

Overview

If you want to show a particular block to some email recipients, but not all, use the email template editor’s show/hide feature. This feature allows you to target your email content based on information about your subscribers, so each recipient has a highly personalized marketing experience. In this article, you’ll learn how to use this feature in your own messaging. 

Before You Start

Before you begin crafting your email, make sure you have the data you need by following the guidelines below.

Collecting Data

You can use show/hide conditions based on profile data in any Klaviyo email. You can use Klaviyo properties or custom profile properties; just make sure the data has been added to Klaviyo before you begin. Profile properties can be added in the following ways: 

Learn more about profile properties in Klaviyo. 

If your email is sent as part of an event-triggered flow (e.g., an abandoned cart or order confirmation flow), you can also show or hide blocks based on the details of that flow’s trigger event. So, in an abandoned cart flow with the trigger Started Checkout, you can build show/hide conditions based on a cart’s value or the specific items the customer added. Learn more about event variables.

Understanding How Data is Stored

Before configuring your show/hide condition, check to see how your data is stored. There are five data types in Klaviyo: 

  • Text
  • Number
  • Date
  • Boolean
  • List

How your data is stored will influence which show/hide condition structures will work for you. Learn how to identify data types in your own account.

Crafting Your Message

The first step to adding show/hide conditions in a message is to build the email template. This section will walk through a specific example. Read on below for guidance on creating show/hide conditions with your own data. 

For example, if your company sells leather bags, you may collect customer preferences for how they use their bags with a signup form, as shown below. 

Signup_form.png

You can then display a different image based on your customer’s bag preference: if the customer’s preference is “Work,” the bag will appear in an image next to a laptop. If the customer’s preference is “Outdoors,” the bag will appear near a scenic overlook on a hiking trail. 

To start, create a campaign or flow message and add an image block. Upload the work-related image to the block, then click the ? icon at the top of the image block settings. Turn the setting on, then add this condition: person|lookup:'Bag Preference' = 'Work'. Click Save in the show/hide modal, then click Save on the block. This block will show only to people who have selected “Work” as their preference. 

Work_preference.png

Next, add in the travel-related image to a new block under the work-related image. Follow the same steps as before, but this time, use the condition person|lookup:'Bag Preference' = Outdoors'. This block will only show to people who have selected “Outdoors” as their preference. 

Outdoor_preference.png

Finally, add in an image to appear for anyone who hasn’t selected either “Work” or “Outdoor.” Use a generic image, and this condition: person|lookup:'Bag Preference' != 'Work' and person|lookup:'Bag Preference' != 'Outdoors'. This block will show to people who have chosen something other than “Work” or “Outdoors,” or have never selected a preference. 

Other_preference.png

Once you’ve configured each of the blocks, preview your message using three profiles. These profiles should be subscribers who meet one of each of the image criteria (i.e., Outdoor, Work, and no preference/other preference) to confirm that the correct image displays. 

You can use these steps to show or hide blocks based on any profile or event data in your account. The sections below outline how to craft your own show/hide conditions. 

Condition Structures

Conditions should include between one and three 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 specific 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. 

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 is set (has any value)

Any

not person|lookup:'Favorite Color'

The Favorite Color property is not set (does not exist on the profile, or is empty)

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

Condition Structures 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

Condition Structures 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

Show/Hide Conditions and Profile Data 

If you are building a show/hide condition based on a profile property, replace the sample variable from the tables above (e.g., person|lookup:'Favorite Color') with your profile property. To do so, use the format person|lookup:'PROPERTY_NAME' and replace PROPERTY_NAME with the name of your property. 

Alternatively, use the Insert Property menu to insert a profile property to a text block. Then, copy the variable name from within the property. To identify the variable name, remove the curly brackets around the variable, as well as |default:'' at the end (if present), along with any other filters

For example, in the screenshot below, the full property is {{ person|lookup:'Accepts Marketing'|default:'' }}. The variable name is person|lookup:'Accepts Marketing', so select that portion to use in your show/hide condition. 

find_profile_property_2.gif

Show/Hide Conditions and Event Data

You can use event data to show or hide a block if your message is part of an event-triggered flow. Only data within the trigger event can be used in a show/hide condition. 

To identify the event variables you can use in your show/hide condition, navigate to the message editor within your flow, then click Preview

In the preview modal, you’ll see sample event data from your most recent event. Scroll through the data to find the variable you want to use, then click that variable. Then, copy the resulting variable tag. 

Note that you don’t need the curly brackets around the variable; you only need the variable text. In the screenshot below, you’ll see the variable tag {{ event|lookup:'Item Count' }}. You’ll only need the text event|lookup:'Item Count' for your show/hide condition. Similarly, if your variable tag was {{ event.extra.line_item.0.title }}, you can extract just the text — event.extra.line_item.0.title — from the tag. 

find_event_property.gif

Using Multiple/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 a series of conditions with AND or 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

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 recipients for your email. 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 the email using a variety of profiles to confirm that the message displays as you intended for all scenarios. 

Additional Resources

x
Was this article helpful?
119 out of 202 found this helpful