Liquid Template Guide

Picture crafting an email template that seamlessly adapts with unique, personalized information. That's what Liquid helps you do. It's like a special recipe book for emails. You write some simple adlib like phrases, and boom! Your email can show different things to different people. Want to greet visitors by name? Show special deals? Liquid makes it possible. It's not super fancy, but it's pretty neat. Check out the basic Liquid guide below to learn its tricks.

The Basics

These essential tags will allow you to personalize your email extensively with links, buttons, images, and even audio to kick things off.

Links are among the most common elements used. They are simple, accessible to users, and very recognizable for their functionality. The liquid tag consists of two parts: a URL and the label. Users familiar with HTML will recognize the components of an HTML ahref tag.

Required Attributes

  • Name
    url
    Type
    Url string
    Description

    Url you want the user to go to when they interact with the link.

  • Name
    hyperlink
    Type
    Label Text
    Description

    The text you want visible for the user to interact with.

{{ "http://example.com" \| hyperlink: "Click here!" }}

Preview

Click Here!


Button

Buttons offer the same functionality as links but come with a distinct, button-like appearance. They are perfect for Call to Actions, making them stand out more effectively than standard links within text.

Their syntax is the same as links, and follows the same rules, avoid using html inside for the link.

  • Name
    url
    Type
    Url string
    Description

    Url you want the user to go to when they interact with the link.

  • Name
    hyperlink
    Type
    Label Text
    Description

    The text you want visible for the user to interact with.

  • Name
    color
    Type
    hexcode
    Description

    HEX code color for the button. You can read more about hex code colors here. Or find some great colors here.

{{ "http://example.com" | button: "Click here!", "#999" }}

Preview


Audio

If you want to link to some audio for your users to enjoy, and their email client supports playback inside the client, there's a tag for that! It also includes a direct link to the audio for clients that don't support playback.

  • Name
    url
    Type
    Url string
    Description

    Public url to the audio file for users to play.

  • Name
    type
    Type
    string
    Description

    Defines this link is an audio file for playback.

{{ 'https://app.bentonow.com/sounds/click.mp3' | audio_tag }}

Preview

If your email client does not support playing audio click here to listen.


Images

Images are worth a thousand words and play an essential visual role in any message, enhancing engagement and comprehension. This versatile image tag supports all HTML versions and options, ensuring compatibility across various platforms. Whether for informative content or captivating visuals, it seamlessly integrates to elevate your web presence.

  • Name
    url
    Type
    Url string
    Description

    Public url to the image file to display.

  • Name
    image_tag
    Type
    string
    Description

    comma seperated list of options, supports in order css classes, id tag, alternate text, width in pixels, height in pixels

{{ 'https://app.bentonow.com/brand/bento-logo-3d.png' | img_tag: "class name", "id", "alt", 100, 200, false }}

Preview

alt


Greeting

Constructs a personalized greeting for the email recipient, formatted with a preference for using their first name, creating a warm and engaging tone that fosters a sense of familiarity and connection right from the start.

{{ visitor.greeting }}

Preview

Hi Jesse,


Formatted Name

Constructs their full name from the name fields provided.

{{ visitor.pretty_name }}

Preview

John Doe


Gravatar Avatar

This feature uses the user's email to show their Gravatar Avatar, ensuring a consistent and recognizable online presence. You can learn more about Gravatar Avatars here.

{{ visitor.email | profile_tag: visitor.pretty_name.first }}

Preview
bento_docs_feedback@bentonow.com John

Operators & Conditionals

If Conditional

This is a fantastic way to showcase content based on subscriber tags. For instance, you can display a thank you message for subscribers who have completed a purchase. But if they have not they won't get the thank you.

{% if visitor.tags contains "customer" %}
This visitor has a 'customer' tag.
{% endif %}

Preview
This visitor has a 'customer' tag.


If/Else Conditional

Once more, this is an excellent method to display content tailored to subscriber tags. Continuing with our example, if they haven't made a purchase, rather than expressing gratitude, you can utilize else to include a CTA encouraging them to buy.

{% if visitor.city contains "New York" %}
You are in New York!
{% elsif visitor.city contains "Sydney" %}
You are in Sydney!
{% else %}
You are on earth!
{% endif %}

Preview
You are in Sydney!


Operators

These options enable math and comparison operations. For instance, if you want to offer a discount to subscribers with more than 10 orders or who have spent over $100, you can use an operator to achieve this.


{% if visitor.order_count >= 10 %}
This visitor has ordered over 10 times!
{% endif %}

Preview
This visitor has ordered over 10 times!

Visitors Reference

Liquid TagResult
{{ visitor.email }}[email protected]
{{ visitor.confirmation_url }}bento confirmation url
{{ browser_url }}
{{ visitor.unsubscribe_url }}users unsubscribe url
{{ visitor.latest_broadcast_url }}
{{ visitor.snooze_url }}
{{ visitor.test_group }}control
{{ visitor.city }}Sydney
{{ visitor.country }}Australia
{{ visitor.is_bot }}true/false
{{ visitor.time_of_day }}
{{ visitor.tags }}Subscribers Tags
{{ visitor.gender }}Male
{{ visitor.path }}
{{ visitor.feedback }}
{{ visitor.first_name }}John
{{ visitor.last_name }}Doe

Liquid Filters

Liquid filters are powerful keywords that instruct Liquid how to manipulate the variables we provide. They are commonly used for tasks such as appending text, rounding numbers, performing basic math operations, formatting data, and sorting lists. These filters go beyond mere inactive template filling; they actively transform and refine the input to produce dynamic, polished outputs. For instance, you can use filters to truncate lengthy descriptions, convert strings to uppercase, or even handle complex date manipulations. By leveraging these versatile tools, developers can create more responsive and interactive web experiences. Ultimately, Liquid filters are essential for anyone looking to maximize the functionality and presentation of their templated content, ensuring that the final output is both accurate and aesthetically pleasing. Below is a list of filters, but you can find the full specification documentation here.

Append

Adds the specified string to the end of another string.

// Liquid Filter
{{ "John" \| append: visitor.last_name }}

John Doe

Capitalize

Makes the first character of a string capitalized and converts the remaining characters to lowercase.

// Liquid Filter
{{ "quick Brown Fox." \| capitalize }}

Quick brown fox.

// Only the first character of a string is capitalized, so later words are not capitalized:
{{ "my GREAT title" | capitalize }}

My great title

Default

Sets a default value for any variable with no assigned value. default will show its value if the input is nil, false, or empty.

// Liquid Filter
// In this example, product_price is not defined, so the default value is used.
{{ product_price | default: 2.99 }}

2.99

// To allow variables to return false instead of the default value,
// you can use the `allow_false` parameter.
{{ display_price | default: true, allow_false: true }}

false

Divide By

Divides a number by another number.
The result is rounded down to the nearest integer (that is, the floor) if the divisor is an integer.

// Liquid Filter
{{ 16 | divided_by: 4 }}
{{ 5 | divided_by: 3 }}

4
1

// divided_by produces a result of the same type as the divisor — that is, if you divide by an integer, the result will be an integer. If you divide by a float (a number with a decimal in it), the result will be a float.
{{ 20 | divided_by: 7.0 }}

2.857142857142857

Downcase

Makes each character in a string lowercase. It has no effect on strings which are already all lowercase.

// Liquid Filter
{{ "Bento Now" | downcase }}

bento now

{{ "apple" | downcase }}

apple

Minus

Subtracts a number from another number.

// Liquid Filter
{{ 4 | minus: 2 }}
{{ 16 | minus: 4 }}
{{ 183.357 | minus: 12 }}

2
12
171.357


New Line Br

Inserts an HTML line break <br /> in front of each newline \n in a string.

// Liquid Filter
{% capture string_with_newlines %}
Hello
there
{% endcapture %}

{{ string_with_newlines | newline_to_br }}

Hello<br />
there<br />


Plus

Adds a number to another number.

// Liquid Filter
{{ 4 | plus: 2 }}
{{ 16 | plus: 4 }}
{{ 183.357 | plus: 12 }}

6
20
195.357


Prepend

Adds the specified string to the beginning of another string.

// Liquid Filter
{% assign first_name = "John" %}
{{ "Doe" | prepend: first_name }}

John doe


Remove

Removes every occurrence of the specified substring from a string.

// Liquid Filter
{{ "The apple fox jumped apple over the apple fence." | remove: "apple" }}

The fox jumped over the fence.


Replace

Replaces every occurrence of the first argument in a string with the second argument.

// Liquid Filter
{{ "The fox jumped over my fence." | replace: "my", "your" }}

The fox jumped over your fence.


Round

Rounds a number to the nearest integer or, if a number is passed as an argument, to that number of decimal places.

// Liquid Filter
{{ 1.2 | round }}
{{ 2.7 | round }}
{{ 183.357 | round: 2 }}

1
3
183.36


Truncate

Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (…) is appended to the string and is included in the character count.

// Liquid Filter
{{ "The fox jumped over the fence." | truncate: 18 }}

The fox jumped ov…

// truncate takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (…), but you can specify a different sequence.
{{ "The fox jumped over the fence." | truncate: 20, ", and so on"  }}

The fox jumped over and so on


Upper

Makes each character in a string uppercase. It has no effect on strings which are already all uppercase.

// Liquid Filter
{{ "Bento" | upcase }}

BENTO


Helpers Reference

Environment Variables

Interact and check the env variables.

Liquid TagResult
{{ ENV.webhooks }}true / false
{{ ENV.laravel }}true / false
{{ ENV.block_form_tracking }}true / false

Encryption

These helpers offer a convenient way to encrypt string values, enabling you to encrypt something for a user on demand without needing to store it for retrieval.

Liquid TagResult
{{ "secret_string" | md5 }}312f946cb92aaa541723382cda411c31
{{ "your secret string" | hmac_sha256: "key" }}63fa337d0a0e6520a12e223657d17184a5e2b131

Time

These tools provide an interface to dynamically work with time, which proves invaluable when managing extensive subscriber lists that necessitate batching. By calculating the precise time for each user when the email is queued for sending, you mitigate concerns about information in the template becoming outdated if a batch is sent several hours later. This ensures that all recipients receive the most current and relevant information. This can also be used for example remind a user that their birthday is coming up in X number of days, or that it's been X number of weeks since they last signed in or made a purchase.

Liquid TagResult
{{ "2010-10-31" | advance_date_to_next: "monday" }}2010-11-01 00:00:00 +0000
{{ "2024-12-31" | days_until }}116
{{ "2024-12-31" | weeks_until }}16
{{ "2022-12-31" | weeks_since }}87
{{ "2022-12-31" | days_since }}614
{{ "2022-12-31" | at_midnight }}2022-12-31 00:00:00 +0000
{{ "2010-10-31" | in_time_zone: "America/Denver" | date: "%Y-%m-%d %H-%M-%S %z" }}2010-10-31 00-00-00 -0600
{{ "2010-10-31" | timestamp }}1288483200
{{ visitor.created_at | time_ago_in_words }}about 2 months

Money

Format money according to the currency assigned to the subscriber or visitor.

Liquid TagResult
{{ money.formatted }}$900.00 USD

Lottery Element

Lottery or randomly pick an element from the provided list. No limitations or weighting applied to elements, ensuring each item has an equal chance of selection.

Liquid TagResult
{{ "Offer One||Offer 2||Offer 3" | split: "||" | pluck_at_random }}Offer 3

Broadcasts

These liquid tags are designed to function specifically within the context of your broadcast and will not work anywhere else.

Liquid TagResult
{{ subject }}Broadcast Subject
{{ name }}Name of the broadcast
{{ created_at }}Timestamp when broadcast was created

Sequences

These liquid tags are designed to function specifically within the context of your sequences and will not work anywhere else.

Cancel the sequence

This creates a hyper link that allows the user to stop the sequence they are in. This helpful to provide subscribers as an alternative to unsubscribe. This is used in the Bento signup drip sequence.

{{ sequence.cancel_sequence_url | hyperlink: "No more emails like this!" }}

Preview
No more emails like this!


Skip forward to the next email in the Sequence

This feature lets you seamlessly skip forward to the next email in the sequence and offers the option to redirect recipients to a specific web URL.

// Skip only
{{ sequence.fast_forward_url | hyperlink: "Instantly get the next email." }}

// Skip and redirect
{{ sequence.fast_forward_url | append: "&redirect=https://bentonow.com/skip" | hyperlink: "Instantly get the next email with redirect." }}

Preview
Instantly get the next email.
Instantly get the next email with redirect.

Ecommerce

Render Last Cart

This feature enables you to display the user's last cart, perfect for reminder emails to encourage users to complete their purchase.

{% assign cart = visitor | current_cart %}
{% for item in cart %}
{{ item.product_name }} - {{ item.product_price }} - {{ item.product_quantity }}
{% endfor %}

Preview

Apple Watch Ultra 2 - 799.00 USD - 1
49mm Indigo Alpine Loop - 99.00 USD - 1
49mm Orange Ocean Band - 99.00 USD - 1


Render Products

This feature allows you to showcase a list of products.

{% for product in products %}
{{ product.product_name }} - {{ product.product_price }} - {{ product.product_quantity }}
{% endfor %}

Preview

Apple Watch Ultra 2 - 799.00 USD - 1
49mm Indigo Alpine Loop - 99.00 USD - 1
49mm Orange Ocean Band - 99.00 USD - 1


Abandoned Cart Checkout URL

A quick and convenient method for generating a personalized URL to seamlessly guide users back into their shopping cart from a reminder email. This makes it easier for users to return to their cart.

Liquid TagResult
{{ abandoned_checkout_url | default: "https://example.com/cart" }}URL string

Stripe and Spotify

These Liquid tags enable you to seamlessly integrate with the Stripe and Shopify platforms, offering convenient methods to generate on-demand coupon codes.

Shopify coupon

Generate a unique coupon code with Shopify.

  • Name
    coupon name
    Type
    string
    Description

    Name for the coupon code.

  • Name
    dicount amount
    Type
    string
    Description

    Defines the discount amount.

  • Name
    discount type
    Type
    string
    Description

    Defines the type of discount valid options: fixed_amount percentage.

{{ visitor | shopify_coupon_generator: "100OFF", "-10", "fixed_amount" }}

Preview

100OFF


Create a distinctive discount code using Stripe

Generate a unique coupon code with Stripe

  • Name
    coupon name
    Type
    string
    Description

    Name for the coupon code.

  • Name
    dicount %
    Type
    string
    Description

    Defines the discount amount.

  • Name
    length
    Type
    string
    Description

    In months how long the coupon will be valid.

{{ visitor | stripe_coupon_generator: "TEST", "10", 5 }}

Preview

TEST


Stripe billing portal link

Create a user-specific Stripe payment portal link.

  • Name
    URL
    Type
    string
    Description

    Name for the coupon code.

{{ visitor | stripe_billing_portal: "https://bentonow.com" }}

Preview

https://bentonow.com

External Data

This feature enables you to seamlessly integrate public data from external sources outside of bento directly into your templates, enhancing the richness and relevance of your content with broader data and context.

RSS | JSON | HTML Parse

You define the url as your data source followed by the type option for how to handle the data. Once you have defined your data you will use a loop to iterate over each item in the returned data.

  • Name
    URL
    Type
    string
    Description

    Name for the coupon code.

  • Name
    type
    Type
    string
    Description

    Supported data types are rss fetch_json youtube fetch_html

{% assign posts = 'https://feedforall.com/sample.xml' | rss %}
{% for post in posts %}
{{ post.title }}
{% endfor %}

Preview

Milk

Eggs

Bread

Gmail Promo

Add Promo Annotation

Promo annotation

  • Name
    promo
    Type
    string
    Description

    What the promo is, often use the amount.

  • Name
    annotation
    Type
    string
    Description

    The supporting annotation to the promo, can be the coupon code.

{{ "20% OFF" | promotion_annotation: "TEST" }}

Was this page helpful?