back arrow
All Blogs
Liquid in Braze

A Beginner’s Guide to Liquid: Personalization And Dynamic Content in Braze

New to Liquid in Braze? Learn in a ridiculously simple language how to implement personalization & dynamic content in Braze by using Liquid....

The significance of personalization is not lost on marketers anymore. 

As a result, business software vendors are enhancing their tools to make implementing personalization more intuitive. 

So the question now isn’t whether personalization is part of your client’s marketing strategy. It most certainly is. 

Rather, do you as a service provider have extensive software expertise? Can you implement personalization on your client’s preferred software or ESP? 

Because software literacy is how you’re going to stand out. 

At Email Uplers, we’re experts at 50+ ESPs, including Braze. All-round software literacy enables us to meet various ESP-specific project requirements to spec. 

In this beginner-friendly guide, Braze is where it’s at. We’re going to show you how to do personalization in Braze using Liquid, a programming language. 

What Is Liquid?

Components of Liquid

Objects in Liquid

Filters in Liquid

Tags in Liquid

Advanced Data Types: Arrays & Objects

Arrays of Objects

Practical Use Cases of Liquid

What Is Liquid? 

Liquid, developed by Shopify, is a programming language written in Ruby, which is used to create dynamic content based on user data. 

Liquid is open-source, meaning it’s available for use by anyone. Compared to more complex coding languages, Liquid is straightforward and easy to learn, making it an excellent tool for marketers looking to personalize their communications.

Key Points:

  • Origins: Developed by Shopify and adopted by customer engagement platforms like Braze
  • Usage: Powers dynamic content in emails, notifications, and more
  • Accessibility: Simple enough for marketers to learn with practice

If you choose to use Liquid in your email messages, be sure to insert it using the HTML editor as opposed to the classic editor.

— Braze

Components of Liquid

Liquid is composed of three main elements, each serving a specific role in creating dynamic content: variables, tags, and filters. 

1. Variables

  • Definition: Variables are placeholders that store data or values
  • Syntax: {{ variable_name }}
  • Functionality: Displays dynamic content, such as a customer’s name or order details.
  • Example: {{ first_name }} displays the customer’s first name.
  • Use Case: Personalize an email greeting with the recipient’s first name: Hello, {{ first_name }}!

2. Tags

  • Definition: Tags control the flow and structure of the template.
  • Syntax: {% tag %}
  • Functionality: Handles logic, loops, and conditions.
  • Example: {% if customer.is_vip %} initiates a conditional block.
  • Use Case: Display a special offer for VIP customers: {% if customer.is_vip %} Exclusive offer just for you! {% endif %}

3. Filters

  • Definition: Filters modify the output of a variable.
  • Syntax: {{ variable | filter }}
  • Functionality: Formats and manipulates data.
  • Example: {{ product.price | currency }} formats the price as currency.
  • Use Case: Format a product’s price to include a currency symbol: {{ product.price | currency }}

In our next section, we’ll explore these basics in a bit more detail.

Objects in Liquid 

Objects represent data points stored in Braze, accessed using standard attributes like {{ first_name }} and {{ email_address }}.

  • Example: {{ first_name }} inserts the recipient’s first name into the email.
  • Use Case: Include a user’s email address in a confirmation message: Your email address is {{ email_address }}

Filters in Liquid

Filters modify content within objects. Examples include:

  • {{ first_name | capitalize }}: Capitalizes the first letter of the first name.
  • {{ first_name | default: 'not here right now' }}: Uses default text if the first name is empty.
  • Use Case: Ensure the first name is always capitalized: Hello, {{ first_name | capitalize }}!

Tags in Liquid

Tags define conditional logic using if, else if, and else statements:

  • {% if first_name %}{{ first_name | capitalize }}{% endif %}: Prints the capitalized first name if it exists.
  • {% if first_name == 'Peter' %}Here is your update{% else %}Hi there{% endif %}: Personalized message based on the name.
  • Use Case: Provide a different message based on the user’s first name: {% if first_name == 'Peter' %} Hello, Peter! {% else %} Hello! {% endif %}

Place Liquid code within the <body> tag only. Placing it outside this tag may cause inconsistent rendering upon delivery.

— Braze

Advanced Data Types: Arrays & Objects

1. Arrays

  • Definition: Lists of items of the same data type.
  • Example: A user’s favorite sports: [“basketball”, “soccer”, “tennis”]
  • Use Case: Display a list of a user’s favorite sports: {% for sport in favorite_sports %} {{ sport }} {% endfor %}

2. Objects

  • Definition: Groups of metadata describing parent data.
  • Example: An item with properties like name, price, and category: {“name”: “T-shirt”, “price”: “20”, “category”: “clothing”}
  • Use Case: Display a product’s details: Product: {{ product.name }} – Price: {{ product.price }} – Category: {{ product.category }}

Arrays of Objects 

  • Definition: Lists of objects.
  • Example: A shopping cart with multiple items, each with properties like name, price, and size: [{“name”: “T-shirt”, “price”: “20”, “size”: “M”}, {“name”: “Jeans”, “price”: “40”, “size”: “L”}]
  • Use Case: Display items in a user’s shopping cart: {% for item in cart %} {{ item.name }} – {{ item.price }} – {{ item.size }} {% endfor %}

Practical Use Cases of Liquid

1. Content Personalization

  • Basic Personalization: Insert the user’s first name or other attributes.
    • Example: Hello, {{ first_name }}!
  • Advanced Use Cases: Customize content based on user behavior or preferences.
    • Example: Show different messages based on the user’s subscription status: {% if user.is_subscribed %} Thanks for being a subscriber! {% else %} Subscribe now for more updates! {% endif %}

2. Multilingual Emails

Create emails that adapt to the recipient’s language preference using Liquid’s conditional logic:

  • Data Preparation: Import user data with language preferences.
    • Example: Use a CSV file with language preferences: id,first_name,last_name,email,language
  • Email Setup: Use Liquid to dynamically adjust content based on language attributes.
    • Example: {% if language == ‘en’ %} Hello! {% elsif language == ‘es’ %} ¡Hola! {% endif %}

Incidentally, you can also add a custome attribute to set your preferred color in the following manner:

{% if {{custom_attribute.${favorite_color}}} == ‘red’ %}

3. Abandoned Cart Emails

Leverage Liquid for loops to create dynamic abandoned cart emails:

  • Data Structure: Store cart items in a custom attribute.
    • Example: {“items_in_cart”: [{“id”: “123”, “name”: “T-shirt”, “price”: “20”}, {“id”: “456”, “name”: “Jeans”, “price”: “40”}]}
  • Loop through Items: Use loops to display each item in the email.
    • Example: {% for item in items_in_cart %} {{ item.name }} – {{ item.price }} {% endfor %}

4. Random Number Generation

Use current time and modulo operations to generate random numbers for various scenarios, like randomizing email subject lines:

  • Example: {% assign random_number = ‘now’ | date: ‘%N’ | modulo: 5 %} {% if random_number == 0 %} Subject Line 0 {% elsif random_number == 1 %} Subject Line 1 {% elsif random_number == 2 %} Subject Line 2 {% elsif random_number == 3 %} Subject Line 3 {% elsif random_number == 4 %} Subject Line 4 {% endif %}

Braze does not currently support 100% of Shopify’s Liquid… We highly recommend testing all messages using Liquid before sending them…

— Braze

Need A Hand to Get Started?

Liquid provides a powerful yet accessible way to create personalized and dynamic content in Braze. By understanding and leveraging variables, tags, and filters, marketers can enhance their campaigns and deliver more relevant messages to their audience. 

If you need help getting started, get in touch with our Braze-certified experts. For more information on this ESP, catch our series on all things Braze.

Did you like this post? Do share it!
Dhrupalsinh Barad

As a seasoned project manager at Mavlers, I bring over nine years of expertise in Project Management, Email Marketing and automation, and Client Servicing. My enthusiasm lies in exploring emerging technologies, which I believe hold immense potential to transform our world positively. When I'm not busy solving problems for our clients, managing teams, or managing projects, you can find me lost in a good book or grooving to dance tracks. Helping others thrive and adding value wherever I can is what keeps me going.

Priyanka C

With three years of experience as an HTML developer at Uplers, Priyanka specializes in email template development, combining technical expertise with creativity. Outside of work, she enjoys reading and staying updated with the latest technological trends to inspire her passion for innovation.

YOU MAY ALSO LIKE

WE CAN ALSO HELP YOU WITH

Email Template
Productions

Transform your requirement into visually-appealing & high-converting email templates.

EMAIL OPERATION
SUPPORT

Focus on your business strategy; let us handle the day-to-day operation of your email campaigns.

DEDICATED
RESOURCE TEAM

Eliminate the woes of hiring and training for resources with our dedicated team of scalable email experts.

Digital
ASSETS

Get more from your paid marketing campaigns through conversion-driven landing pages and banners.