Sticky MPKnowledgedrop

Liquid templating examples for email and other messages

  • 13 November 2019
  • 6 replies
Liquid templating examples for email and other messages
Userlevel 6
Badge +4

Every week, we will release tips to help you get the most out of Mixpanel. Want to see more? Click here to see other #mpknowledgedrop articles.


If you read our Liquid Templating article and want to get better at it, then keep reading our MPKnowledgeDrop! In this post we will share Liquid Templating examples on email and other message types!

What is personalization and why should I do it?

Personalization is all about sending messages that are tailored to each unique user.

Liquid is a templating language developed by Shopify, which you can use to personalize text in your Mixpanel messages. Personalization can range from the simple variable insertion to complex iterations and substitutions.

Variable insertion

The most common personalization is to pull in fields like a person’s name, their city, etc. This works similarly across message types. For example, if you want to increase how many people open your emails, you might use a variable to address them by name.

Hi {{ user[‘$first_name’] }}, welcome to Mixpanel!


Now, what if you didn’t always track the variable $first_name for every one of your users. You can specify a default value to be used if you don’t have the person’s name.

Hi {{ user[‘$first_name’] | default:’there’ }}, welcome to Mixpanel!


For a user named Robert, this would read “Hi Robert, welcome to Mixpanel!”. However, if a user didn’t have a first name stored in their Mixpanel people property, it would read “Hi there, welcome to Mixpanel!”

Sometimes, you may have tracked names without capitalizing them. This is an easy fix too. You can just use the special capitalize keyword

Hi {{ user[‘$first_name’] | capitalize | default:’there’ }}, welcome to Mixpanel!

If the user’s first name is stored as “robert”, this will read “Hi Robert, welcome to Mixpanel”

Variable insertion can be used in many different parts of various messages. You can use variables in an email subject, body, reply-to address, from name, and bcc address. For example, in the message below, we’ve used the CSM’s name and email when reaching out to a new customer.




Conditionals are the second most common type of personalization. You may want to send the same email/SMS/push notification with differences for different groups. The most common use-case for this is language localization, where you want to send different content to different users.

In the example below, if a user named Robert who has his language set to French will see their message as “Bonjour Robert!”

{% if user['Language'] == 'spanish'  %} Hola {}! {% elsif user['Language'] == 'french' %} Bonjour {}! {% else %} Hello {}! {% endif %}



However, you may also want to divide people based by lifetime value or plan type.

In the example below, we are using conditionals to tell people what discount programs they are eligible for. In addition to text, we are also capturing a discount multiplier that we can use to figure out what their price is. The liquid syntax {% assign var_name = value %} creates a variable that can be used in subsequent parts of the text to help modify it.

{% if user[‘company_launch_year’] >= 2016 %} You may be eligible for our startup program discount!  {% assign discount_multiplier = 0.75 %} {% elsif user[‘company_type’] contains ‘non-profit’ or user[‘company_type’] contains ‘charity’ %} You may be eligible for our non-profit discounts! {% assign discount_multiplier = 0.70 %} {% else %} {% assign discount_multiplier = 1 %} {% endif %} 



Liquid supports iteration through lists. This is really helpful in cases where you may have objects as user properties and need to do things like render shopping carts or set up recommendation lists.

<div>{% assign total = 0 %}{% assign foo = user["shopping_cart"] %}{% for item in foo %}{% assign temp_price = {}}} %}{% assign total = total | plus: {} %}{% endfor %}<table style="width:100%" border="1"><tbody><tr><th>Image</th> <th>Item</th><th>Price</th><th>Quantity</th><th>Total</th></tr><tr><td><img src="{}" height="200"></td><td>{}</td><td>${}</td><td>x{}</td><td>${}</td></tr><tr><td bgcolor="gray"></td><td bgcolor="gray"></td><td bgcolor="gray"></td><td bgcolor="gray"></td><td>${}</td></tr></tbody></table><div><br></div>


You can also set up liquid in push and SMS messages. For example, in a push message you can use the body or the custom data field to add liquid templating.


Here is an example of an iOS push -

{ "aps":{ "alert":{ "body":"{% if user['language'] == 'French' %} Bonjour {% elsif user['language'] == 'Spanish' %} Hola {% elsif user['language'] == 'German' %} Hallo \n Brother {% else %} Hello {% endif %}" } } }



These are just some common Liquid examples to get you started. Go do something cool with Liquid in Mixpanel and share it with us!


6 replies

i try to search about example of abandoned email reminder that i can add automatically products names and images to reminder email sent automatically to user, How can i do this ? 

Userlevel 5
Badge +3

Hi @anasemadmix, can you share more details or an example of what you are trying to set-up? 

Hey @cherise, I’m facing an error while using {{$first_name}} in subject of an email.

using {{$first_name}}


Userlevel 6
Badge +4

 @anasarshad it looks like you are using Mixpanel’s Dynamic syntax instead of the Liquid Templating in your subject line (read more on the differences here). I would recommend using Liquid Templating syntax to target your user properties in your email subject line because Mixpanel’s Dynamic feature will be deprecated on December 2020

When using Liquid in emails, you need to check the "Advance templating (liquid)" box at the bottom of the email builder.  Once you have liquid turned on, you can target your user properties.


Example of a liquid syntax,



You can read more on how to use Liquid templating language in our help documentation here

Let me know if this helps!

Thanks @stephanie !

@stephanie Copying your example 1:1 gives a syntax error. Have you changed the syntax since you wrote this?

Hi {{ user[‘$first_name’] | default:’there’ }}, welcome to Mixpanel!