You will learn
Learn how to use Klaviyo’s template tags and variables to personalize your marketing messages and provide a customized experience for your subscribers.
Variables are used to populate a customer’s information (like their first name, location, or interests) in a template. In addition, in a metric-triggered flow, variables can populate details from the event that triggered the flow (like the items in someone’s order, or a shipment tracking number). Variables are surrounded by a pair of curly brackets, and look like this: {{ person.email }}
Template tags are a pre-defined set of tags that can be used to populate things like an unsubscribe link or today’s date. Template tags are surrounded by a set of curly brackets and the percent symbol, and look like this: {% unsubscribe_link %}
Variables and template tags can be used in emails (including the email’s subject line) and SMS/MMS messages.
These steps refer to Klaviyo's new template editor. If you are working in a classic editor template, create a new template to use the new editor.
Using variables
When you input variables into a text, table, or other block type, they look like the sentence on the left in the table below. Once you send the email, the variables are replaced by information from the recipient’s profile or event details, and will look like the sentence on the right.
Hi |
Hi George Washington, your favorite color is Green |
Profile variables will generally begin with person
, with the exception of a few special variables like first_name
and last_name
. Event variables, which can be used in metric-triggered flows, begin with event
.
To add a variable to a template, first decide which variable type you need:
-
Profile variable
Information stored on a person’s profile -
Event variable
Details about a specific metric or action the person took
How to add a variable
There are multiple ways to add profile and event variables to templates, including selecting them via the preview modal or adding them manually. The data available to use in your emails is based on the data you’ve historically collected, and will differ for every Klaviyo user. You can find all properties available to use in your emails using the preview modal for emails and SMS messages.
Adding profile variables to email and SMS messages
To add a profile variable to an email template:
- Click Preview and test from the template editor
- Click Search for a profile and enter the email of a profile that includes the variable you’d like to add
- Scroll through their Profile properties and Custom properties until you find the variable you’d like to use
- Hover over the variable’s name until you see the message Copy {{ person.variable_name }} variable, then click to copy it
- Click Done
- Paste the variable into a block in your template
To add a profile variable to an SMS message:
- Click the i icon to view profile details
- Click the search icon and enter the email or phone number of a profile that includes the variable you’d like to add
- Scroll through their Profile properties and Custom properties until you find the variable you’d like to use
- Hover over the variable’s name until you see the message Copy {{ person.variable_name }} variable, then click to copy it
- Paste the variable into a block in your message
Adding event variables to email and SMS messages
Your message must be sent through a metric-triggered flow triggered by the event you select in step three in order for the variables to populate. Only use variables from one metric in a template. However, you may also use profile variables in a template that uses event variables.
To add an event variable to an email template:
- Click Preview and test from the template editor
- Under Preview data source, click Event
- Select an event from the dropdown
- Scroll through the Event properties until you find the variable you’d like to use
- If you don’t see the variable you need, use the arrows to the right of Previewing with recent event: to select a different instance of the event
- Hover over the variable’s name until you see the message Copy {{ event.variable_name }} variable, then click to copy it
- Click Done
- Paste the variable into a block in your template
To add an event variable to an SMS message:
- Open an SMS message in a metric-triggered flow
- Click the i icon to view event details
- Use the arrow buttons to find an event that includes the variable you’d like to add
- Scroll through their Event Properties until you find the variable you’d like to use
- Hover over the variable’s name until you see the message Copy {{ event.variable_name }} variable, then click to copy it
- Paste the variable into a block in your message
Variable formats
You always have the option to select variables from the preview modal by following the instructions above. However, you can also add variables manually using the formats listed in the table below.
Variable format |
Description |
Example |
|
A simple profile variable |
person.email |
person|lookup:'variable name' |
A profile variable, if the variable name contains spaces or special characters |
person|lookup:'Favorite Color' |
event.variable_name |
A simple event variable |
event.URL |
event|lookup:'variable name' |
An event variable, if the variable name contains spaces or special characters |
event|lookup:'$value' |
|
An event variable name, if the event variable is nested in the event data |
event.extra.checkout_url |
event|lookup:'variable name'|lookup:'nested variable name' |
An event variable name, if the event variable is nested in another variable with a name containing a space or special character |
event|lookup:'Coupon Codes'|lookup:'0' |
Use dot (.) notation to specify variable names with no spaces or special characters. If your variable names do contain spaces or special characters (e.g., $), use lookup notation.
Note that, with nested variables, if one variable name uses lookup notation, all later variables must also use lookup notation. This means that event|lookup:'Collection
Names'|lookup:'0'
is correct, but event|lookup:'Collection Names'.0
is not.
Finally, make sure to surround your final variable with curly brackets. Using curly brackets allows Klaviyo to identify which parts of your email are dynamic variables, and which are simple text. A properly formatted variable might look like this:
{{ person.variable_name }}
Customizing variables
To customize the way your variables appear, apply template filters. Filters can be used to apply title case, set the number of decimal places for a number, and much more. Two of the most common filters are default
and title
.
The default
filter allows you to set a default value to appear if a message recipient doesn’t have that variable set. In the example below, 'friend' and 'tasty treats' are set as the default values in case a recipient’s name or favorite food is not set in their Klaviyo profile.
Text with variables |
Output |
Hey |
Hey friend, any interest in some tasty treats? |
The title
variable allows you to apply title casing to any text variable, to ensure it appears consistently once the message is sent. For example, some subscribers may use all capital or all lowercase letters when they fill out your signup form. Without a filter, their first name would use the casing they initially used when filling out your form. However, the title filter corrects the casing so their name appears correctly.
Text with variables |
Output |
Hey |
Hey Elise, have you seen our latest launch? |
There are dozens of other filters available for your messages. Learn more about using filters to customize variables.
Account variables
Account variables allow you to include information about your company or organization in your email. You can manage this information by navigating to Account > Contact Information > Organization. All account variables start with organization
. See the table below for the list of account variables.
Organization variable |
Description |
|
Your organization’s name |
{{ organization.url }} |
Your organization’s website |
{{ organization.full_address }} |
Your organization’s full address, including city, state/region, and zip code |
{{ organization.street_address }} |
Your organization’s street address |
{{ organization.street_address2 }} |
The second part of your organization’s address (e.g., apartment or unit number) |
{{ organization.city }} |
Your organization’s city |
{{ organization.region }} |
Your organization’s state, province, or region |
{{ organization.zip_code }} |
Your organization’s zip code |
Using template tags
Template tags allow recipients to manage their subscription preferences and view your campaign in their browser.
Unsubscribe, Manage Preferences, Web View, and Preview Text tags are only supported for email templates, not for SMS/MMS.
Unsubscribe
Klaviyo requires an unsubscribe link in all emails. The easiest way to add an unsubscribe button is the {% unsubscribe %}
tag, which populates a simple text button. When you add this tag to a text block, it will be replaced at send time with the word “Unsubscribe”. You can also add a pair of single quotes to the tag containing any alternate text or translation you’d like to use, like in the table below.
Variable |
Output |
{% unsubscribe %} |
Unsubscribe |
If you'd no longer like to receive emails, |
If you'd no longer like to receive emails, click here. |
Alternatively, you can use the {% unsubscribe_link %}
tag to generate an unsubscribe URL. Rather than generating a full linked word or phrase, this tag creates just the unsubscribe URL. Use this tag if you’d like to use a different color for your unsubscribe link than the link color set in your template’s styles, or use a linked button or image rather than a text link.
Variable |
Output |
This is a fancy <a href="{% unsubscribe_link %}" >unsubscribe</a>
link.
|
This is a fancy unsubscribe link. |
When a recipient clicks the unsubscribe link, they're taken to a page to confirm their unsubscribe request. You can see everyone who has unsubscribed by navigating to Profiles > Suppressed Profiles and choosing unsubscribe in the reason dropdown.
Manage preferences
You can create preference pages and customize them to match your brand. This allows recipients to update their preferences. To include a link to this page for each recipient, use the manage preferences tag. If you need more control, there is also a version that just provides the URL.
You can create list-specific and general manage preference pages. List-specific pages are sent when you send a message to just one list. The general manage preferences page is used when you send to a segment, a combination or lists, and in flows that are not list-triggered. Learn more about manage preferences pages.
The easiest way to add a manage preferences button is the {% manage_preferences
%}
tag, which populates a simple text button. When you add this tag to a text block, it will be replaced at send time with the words “Manage Preferences”. You can also add a pair of single quotes to the tag containing any alternate text or translation you’d like to use, like in the table below.
Variable |
Output |
{% manage_preferences %} |
Manage Preferences |
Want to update your preferences? |
Want to update your preferences? Click here. |
Alternatively, you can use the {% manage_preferences_link %}
tag to generate a manage preferences URL. Rather than generating a full linked word or phrase, this tag creates just the URL for the recipient’s preference page. Use this tag if you’d like to use a different color for your link than the link color set in your template’s styles, or use a linked button or image rather than a text link.
Variable |
Output |
This is a fancy <a href="{% manage_preferences_link %}" >manage
preferences</a> link.
|
This is a fancy manage preferences link. |
Web view
To give recipients the option to view an email in their web browser, you can use the web view tag. Like other template tags, if you need more control, there is also a version that just provides the URL.
Variable |
Output |
{% web_view %} |
View in Your Browser |
Can't see this email? |
Can't see this email? Open in your browser. |
This is a fancy <a href="{% web_view_link %}" >web view</a>
link.
|
This is a fancy web view link. |
Preview text
In some cases you may want to display your preview text inside the body of your template. You can reference any preview text you set on the email preview screen by using this email template tag: {% render_variable preview_text %}
.
If you update the preview text on the email preview screen, this tag displays your updated preview text.
Date tags
Date tags give you a quick way to insert date information into an email. The date is in the timezone of your account, and reflects the day or time a message was sent.
The today tag is one of the most common date tags, and it populates a timestamp when the message is sent. To use the today tag, paste the following code into your template:
{% today "%Y-%m-%d" as today %} {{ today }}
To learn how to use or customize date tags, head to our article How to Format Date Variables in Templates.
Conditional statements
Conditional tags allow you to include content in your messages for recipients who meet certain criteria, and not include it for others. They give you powerful controls for personalizing your messages for each recipient.
If statements
If statements allow you to control the content someone receives based on profile or event data.
In the example below, a person will be shown the first line of text if they have more than 150 loyalty points. If they have less than 150, but more than 0, they will see the second line. And if they have no loyalty points, they will see the third message.
{% if person|lookup:'Loyalty Points' > 150 %}
Hey VIP! You’ve always got free shipping & free returns {% elif person|lookup:'Loyalty Points' > 0 %}
You have {% else %}
Have you heard about our VIP program? Join today on our website to start earning rewards. {% endif %}
|
Within an if statement, an initial {% if … %}
condition is required, as well as the closing {% endif %}
tag. All other elements (i.e., {% elif %}
and {% else
%}
tags) are optional. You can use an unlimited number of {% elif %}
tags, followed by a maximum of one {% else %}
tag. Each email recipient will only see the first message they qualify for.
For statements
"For" blocks allow you to iterate over each item in a variable that's storing a list and render them individually. Below is an example statement:
{% for item in event.shopping_cart_items %}{{ item.name }} ×
{{ item.quantity }}
{% endfor %}
|
Oversized Beach Blanket × 1 Beach Chairs × 430 SPF Sunscreen × 220 Plastic Cooler × 1 |
Each For statement must contain the following:
- An opening
{% for … %}
tag, containing a row alias (item in the example above) and row collection (event.shopping_cart_items in the example above) - A closing
{% endfor %}
tag
Between the two required tags, you can include any text you’d like. To include variables nested within the row collection, replace the beginning of the variable name (the row collection plus the number following the row collection) with your row alias. For example, the variable {{ event.shopping_cart_items.0.name }}
would become {{ item.name }}
.
Next steps
Ready to learn more about templates in Klaviyo? Head to our Templates Showcase to get inspired or take our course, Getting Started with Email Design.
Additional resources
- How to show or hide template blocks and sections based on dynamic variables
- How to use sections in email templates
- How to build dynamic blocks in a flow email