Menu
 

Customer.io Liquid tag master list

This doc should give you an idea of which Liquid tags and variables are available to you in Customer.io. Our version of Liquid is currently 2.5.3, so that dictates what we have available, as we’re behind the original source code. We do also have some Liquid specific to Customer.io you can use. Read on!

What’s specific to Customer.io

Tags

The Liquid What does it do?
{{content}} the tag used in layouts to indicate where the code added via the email editor will be included
{% unsubscribe_url %} This tag renders a unique unsubscribe link for that customer and email.
{% view_in_browser_url %} Our default link that generates a web version of your email, personalized for each recipient. Looks something like: http://e.customeriomail.com/deliveries/…
{{layout.id}} The numerical ID associated with the email layout you've used.
{{layout.name} The name you've assigned to the email layout you've used.
{{campaign.id}} Your campaign's numerical ID. This can be found in your campaign URL. For example, the campaign ID here is 2000: https://fly2.customer.io/env/12345/v2/campaigns/2000/overview
{{campaign.name}} This tag will output the name you've given your campaign in the Customer.io interface. For example: "Q2 Anvil Onboarding Campaign [Coyotes]"
{{campaign.type}} This returns whether or not your campaign is behavioral (segment triggered), transactional (event triggered), or a newsletter
{{message.id}} The numerical ID associated with the specific email the link belongs to.
{{message.name}} The name you give your message in the workflow. E.g. "Welcome to ACME!"
{{message.type}} This refers to a particular message's type. Possible values are: email_action, twilio_action, slack_action, webhook_action, urban_airship_action, attribute_update_action
{{message.subject}} If your message has a subject (or if it's different to the message name) this tag will echo it.
{{event_timestamp}} The UNIX timestamp for when a particular event was performed. Keep in mind that this is different from 'now'!
now The current time in UTC. Needs to be formatted with date. e.g. {{ 'now' | date: "%H:%M %p %B %d, %Y" }} returns the current time in this format: 06:54 AM August 31, 2017

Filters

The Liquid What does it do?
round Rounds a number to the nearest integer. e.g.{{ 4.6 | round }} will output 5.
number_to_currency Formats a number into a currency. e.g.{{ 8 | number_to_currency }} outputs $8.00We don't have the locale: option here.
rounded_currency Rounds a number into the nearest whole integer, and formats it to a currency. e.g.{{ 8.01234 | number_to_currency }} outputs $8. We don't have the locale: option here.
urlencode Escapes/encodes any URL-unsafe characters in a string. e.g.{{ "Hello, world!" | urlencode }} outputs Hello,%20world!.
htmlencode Escapes/encodes reserved HTML characters in a string. e.g.{{ "<p>Hello, world!</p>" | urlencode }} outputs <p>Hello, world!</p>.
escape Escapes/encodes all special characters e.g.{{ "Hello, world!" | urlencode }} outputs Hello%2C%20world%21.
base64 Base64-encodes a string. {{ 'Hello, world!' | base64 }} returns SGVsbG8sIHdvcmxkIQ==.
add_year Adds a year, or multiple years, to a given timestamp e.g.{{ 1477430251 | add_year }} outputs 1508966251. You can also use {{ 1477430251 | add_year: 4 }}
add_month Adds a month, or multiple months, to a given timestamp e.g.{{ 1477430251 | add_month }} outputs 1480108651. You can also use {{ 1477430251 | add_month: 2 }}
add_day Adds a day, or multiple days, to a given timestamp e.g.{{ 1477430251 | add_day }} outputs 1477516651. You can also use {{ 1477430251 | add_day: 7 }}
timezone Converts a timestamp to a timezone you specify. e.g.{{ 1483272000 | timezone: 'US/Pacific' | date: "%H:%M, %a, %b %d, %Y"}} outputs 04:00, Sun, Jan 01, 2017. You can also use 'now' instead of a timestamp. Timezone inputs can be: timezone: '-3' (specify your number) or UTC
to_json Ouputs the json representation of the input e.g.{{ customer | to_json }} will send all your customer data into a JSON variable.
random Generates a random number between 0 and NUM. e.g.{% random 10 %} ill generate a random number between 0 and 10.

Standard Liquid

The Liquid What does it do?
date Reformat a date. e.g. {{ 1483272000 | date: "%H:%M, %a, %b %d, %Y"}} will output 12:00, Sun, Jan 01, 2017. Here's a syntax reference
capitalize Capitalize the first character in a string. e.g.{{ "hello, world" | capitalize }} will output Hello, world
downcase Converts a string to lower case. e.g.{{ "ACME" | downcase }} will output acme
upcase Converts a string to upper case. e.g.{{ "acme" | upcase }} will output ACME

Array Filters

For the first few examples, assume you have this array: acme.characters = "coyote", "bugs", "tweety".

The Liquid What does it do?
first Returns the first element of the array. e.g. {{ acme.characters | first }} will output coyote
last Returns the last element of the array. e.g. {{ acme.characters | last }} will output tweety
join Joins the elements of an array with the character passed as the parameter. e.g.{{ acme.characters | join: ', ' }} will output coyote, bugs, tweety
sort Sorts the elements of an array by a given attribute of an element in that array. Usually used with a 'for' loop. See this example, and remember that the order of the sorted array is case-sensitive!
map Creates an array of values by extracting the values of a named property from another object. If you have the object: "[{"name":"coyote"},{"name":"bugs"},{"name":"tweety"}]", you can use map like this, to create a new array of the character names:

{% assign names = customer.characters | map: 'name' %}

. Then, to output them, you can use a 'for' loop. See syntax.
size Returns the size of a string (in characters) or an array (number of elements). e.g.{{ "That's all, folks!" | size }} will output 18

String Filters

The Liquid What does it do?
escape Escaping (or encoding) a string removes special characters. e.g.{{ "Hey there, world!" | escape }} will output Hey%20there%2C%20world%21
escape_once Escapes or encodes a string, but doesn't include already-escaped characters. e.g.{{ "1 < 2 & 3" | escape_once }} will output 1 < 2 & 3
strip_html Removes HTML characters from a string. e.g.{{ "Eh, what's up, Doc?" | strip_html }} will output Eh, what's up, Doc?
strip_newlines Removes line breaks (\n) from a string. e.g.{{ product.description | strip_newlines }} will remove all line breaks from your product description, if there are any.
newline_to_br Replaces line breaks (\n) with
. See this example for output.
replace Replace each occurrence of A with B. e.g.{{ "Coyotes never catch roadrunners!" | replace: "never", "always" }} will output Coyotes always catch roadrunners!
replace_first Same as above, but only replaces the first instance of A. e.g.{{ "roller rocket roller skates" | replace_first: "roller", "awesome" }} will output awesome rocket roller skates
remove Removes a specified item from a string. e.g.{{ "And that's all, folks!" | remove: ", folks" }} will output And that's all!
remove_first Removes the first occurrence of a specified item from a strong. e.g.{{ "folks that's all folks!" | remove_first: "folks" }} will output that's all folks!
truncate Shortens a string down to the given number of characters, adding an ellipsis. e.g.{{ "I knew I shoulda taken that left turn at Albuquerque." | truncate: 20 }} will output I knew I shoulda ...
truncatewords Shortens a string down to the number of words passed, instead of characters, and adds an ellipsis. e.g.{{ "I knew I shoulda taken that left turn at Albuquerque." | truncatewords: 8 }} will output I knew I shoulda taken that left turn...
prepend Adds a specified string to the beginning of another string. e.g.{{ "Sufferin' succotash!" | prepend: "Sylvester: " }} will output Sylvester: Sufferin' succotash!
append Puts together two strings. e.g.{{ "What's all the hubbub, " | append: "bub?" }} will output What's all the hubbub, bub?
split Divides an input string into an array using a separator you define. Often used with a for loop. See this Beatles example.

Math Filters

The Liquid What does it do?
minus Subtracts a number from another number. e.g.{{ 10 | minus: 1 }} will output 9
plus Adds a number to another. e.g.{{ 10 | plus: 1 }} will output 11
times Multiplies a number by another. e.g.{{ 5 | times: 2 }} will output 10
divided_by Divides a number by a number you specify. e.g.{{ 10 | divided_by: 4 }} will output 2, while {{ 10 | divided_by: 4.0 }} will return 2.5
modulo Returns the remainder of division. e.g.{{ 3 | modulo: 2 }} will output 1
currency Converts an integer to currency. e.g.{{ 10 | currency }} will output $14.00

Tags

For all of these, you can see specific syntax here.

The Liquid What does it do?
comment Doesn't show the content inside of it. e.g.{% comment %}Don't display me!{% endcomment %}
assign Assigns a specific value to a variable. e.g.{% assign favorite_food = 'apples' %} creates {%raw%}{{ favorite_food }}.
capture Captures a string and assigns it to a variable. e.g.{% capture about_me %}I am 28 and my favorite food is pasta.{% endcapture %} creates {{ about_me }}.
case Creates a switch statement that depends on a variable's specific value. For example, you might use this to display different text depending on if a customer lives in a specific country.
cycle Loops through strings and outputs them in the order they were passed. It needs to be used in a 'for' loop! So if you have the array ["coyote","bugs","tweety"] held in a customer attribute, you can do this: {% for character in customer.characters %} <li class="{% cycle 'odd', 'even' %}>{{ character }}</li>{% endfor %}

This will output:
  • coyote
  • bugs
  • tweety

  • With alternating 'odd' and 'even' CSS classes, like this: <li class="odd">coyote</li> <li class="even">bugs</li> <li class="odd">tweety</li>
    for Repeatedly executes a block of code. See syntax here.
    if Executes a block of code if a certain condition is met. See syntax here.
    unless Like if, but this code is executed if a certain condition is not met. See syntax here.
    raw Temporarily disable Liquid processing. See syntax here.

    Need help?

    For all of the above tags, we have our own syntax guide which we’ve linked above. If you need specific guidance wth how to use a particular tag with Customer.io, let us know!