List of Liquid functions / dynamic templating variables

Below are some useful liquid functions you can use when working with dynamic data in Vero. For a more general guide to using dynamic data in Vero, read our help doc on personalising emails with data.

Number precision

This works with any Liquid variable which are numbers.

Here is an example:

{{item.price | precision: 2}}

Utilities

There are a number of convenience functions you can use in Vero.

{%random 20%} => 15 (inserts a random number between 0 and the number specified)
{%capture a_variable%}{%random 20%}{%endcapture%}
{{a_variable}} => 15

user.email = "support+test@getvero.com"
{{user.email | base64_url_safe_encode}} => c3VwcG9ydCt0ZXN0QGdldHZlcm8uY29t

user.email = "support+test@getvero.com"
{{user.email | md5}} => 20e815c8877d46cd29d162754b0f2773

user.email = "support+test@getvero.com"
{{user.email | sha1}} => 1e71615687de8192e23949040adc380ade233f3c

Formatting

This works with any Liquid variable which are character, decimal (integer) number (base 10), exponential floating-point number, floating-point number, integer (base 10), octal number (base 8), a string of characters, unsigned decimal (integer) number, number in hexadecimal (base 16)

It follow the basic printf formatting specifiers ( Printf format cheat sheet)

Here is an example:

event.invoice_ref = 12345
{{event.invoice_ref | format: '%05d'}} => 12345

event.invoice_ref = 123
{{event.invoice_ref | format: '%05d'}} => 00123

event.invoice_ref = 1
{{event.invoice_ref | format: '%5d'}} => '    1'

You can also humanize integers using the 'humanize' method:

event.price = 10
{{event.price | humanize}} => ten

Encoding

This is primarily useful when you want to pass variables such as email address to URL params.

Here is an example:

user.email = 'damien+test@getvero.com'
{{ user.email | encode }} => 'damien%2Btest%40getvero.com'

Date/Timezone precision

This works if you track a date following the ISO 8601 format

Timezone and Formatting

Here are some examples:

purchase_date = "Thu Nov 29 2001 14:33:20 UTC"
{{ purchase_date | time_zone: 'Sydney' }} => 2001-11-30 01:33:20 +1100

purchase_date = "29/11/2001 00:00:00 -0900"
{{ purchase_date | time_zone: 'Sydney' }} => 2001-11-29 20:00:00 +1100

purchase_date = "Thu Nov 29 2001 14:33:20 UTC"
{{ purchase_date | time_zone: 'Sydney' | date: '%d/%m/%Y %H:%M:%S %Z' }} => 30/11/2001 01:33:20 EST

purchase_date = "2015-12-01 10:00"
{{ purchase_date | time_zone: -7 | date: '%d-%m-%Y %H:%M' }} => 1-12-2015 03:00

with_locale

We provide a with_locale filter that will format the date in the language of the locale passed to the filter.

purchase_date = "2015-04-01 11:33"
{{ purchase_date | with_locale: '%Y %b %H:%M', 'es-MX' }} => 2024 abr 11:33

You can also pass it a user property.

purchase_date = "2015-04-01 11:33"
user.locale = "es-MX"

{{ purchase_date | with_locale: '%Y %b %H:%M', user.locale }} => 2024 abr 11:33

extra.time.now

We provide a custom Liquid variable which lets you access the current time (at the time a newsletter is compiled). To do so, use the code extra.time.now. This will return the current datetime as a Unix integer value. You can transform this value using the date filter in Liquid. Here is a complex example. This example would result if it was run at 11:37pm 12 November (UTC).

{{ extra.time.now | date: "%Y-%m-%d %H:%M" | time_zone: -7 | date: "%Y %h %d %H:%M" }} => 2015 Nov 12 16:37

View the full list of timezones you can use.

date_modify

We provide a filter for working with dynamic dates called date_modify. This filter takes a string like +7 days or -7 days and adds or subtracts that time from the timestamp. It must be prefixed with either a + or -, and can take any of the following units: years, months, days, hours, minutes.

In these examples, the value of "now" is 2024-09-04 17:00.

{% assign date = extra.time.now | date_modify: '-45 days' %}
{{ date | date: '%Y-%m-%d' }} => 2024-07-21

{% assign date = extra.time.now | date_modify: '-1 years' %}
{{ date | date: '%Y-%m-%d' }} => 2023-09-04

{% assign date = extra.time.now | date_modify: '+5 days' %}
{{ date | date: '%Y-%m-%d' }} => 2024-09-09

{% assign date = extra.time.now | date_modify: '+1 hours' %}
{{ date | date: '%Y-%m-%d %H:%M' }} => 2024-09-04 18:00

For even more information about using liquid in Vero, read our detailed liquid guide.

Authors

  • Chris Hexton
    CEO and Co-Founder