Liquid Pro: The Liquid template language

The Liquid is a template language, which makes easier to create signatures and campaigns with complex logic and data formatting.

Liquid supports a wide variety of built-in tags, objects, and filters, and you'll be able to find the one suitable for your requirements. But the most efficient feature of Liquid is that you can combine these tags, objects, and filters, nest one conditional statement within another. Liquid increases the possibility to reach the most desirable view of the signature for each employee and make their personal information render in the exact format you need - without relying on the data format synced from your source.

Example#1

You synced the phone number from your AD into Xink in this format +1 9083408836 / +1 9083408836x123 and your task is to make it render in the signature of the end-user this way:

  1. show the number in this format 908 340 8836 and if it has an extension, then show it like this - 908 340 8836 x123;
  2. remove the numbers from the signatures of those employees, who don't have them in their entries in Xink.

While it's far from the trivial tasks to manually change this info in 100-2000 employees' entries in your AD or Xink, Liquid allows reaching this output with just a few filters in only 1 signature for all your employees at once. Easy and efficient!

{% if DirectPhone == blank %}{% else %}{% if DirectPhone | contains: 'x' %}{{DirectPhone | substr_after: '+1' | phone_format: '000-000-0000 x000'}} (direct)
{% else %}{{DirectPhone | substr_after: '+1' | phone_format: '000-000-0000'}} (direct)
{% endif %}{% endif %}

Example#2

You want to add the specific campaign in the signature for the limited group of your employees, who match 4 filters at once. While Campaign Rules allow filtering max 2 fields at once, Liquid provides the opportunity to check as many fields as you want simultaneously.

If the Country is Denmark and Office is not A080 and not A020 and not A310, then show this specific campaign.

{% unless Office | contains: 'A080' or Office | contains: 'A020' or Office | contains: 'A310' %}{% if Country | contains: 'Denmark' %}{{ campaign[16041] | raw }}{% endif %}{% endunless %}

Discover Liquid instructions

Don't use CASE, IFNULL and NULL together with Liquid in one template.

CASE, IFNULL and NULL don't work with Liquid. Don't combine them in one template together.

Objects

Objects tell Liquid where to show content on a page. Objects and variable names are denoted by double curly braces: {{ and }}.

  • Object fields contains employee's fields data 
    {{ Email }}
    {{ fields.Email }}
    {{ fields["Email"] }}
  • Object shared_fields is very similar to fields, but contains SHARED employee's fields data 
    {{ shared_fields["Email"] }}
  • Object campaign contains active campaigns 
    {{ campaign[11856] | raw }}
Tags

Tags create the logic and control flow for templates. They are denoted by curly braces and percent signs: {% and %}.
The markup used in tags does not produce any visible text. This means that you can assign variables and create conditions and loops without showing any of the Liquid logic on the page.

  • if
    Executes a block of code only if a certain condition is met (that is, if the result is true).
    {% if Email | contains: 'xink.io' %} Email contains 'xink.io' {% else %} Email does not contain 'xink.io' {% endif %}
    {% if Mobile == blank %}{% else %}M: {{Mobile}}{% endif %}{% if Mobile == blank or Phone == blank %}{% else %} | {% endif %} {% if Phone == blank %}{% else %}T: {{Phone}}{% endif %} {% if Phone == blank or DirectPhone == blank %}{% else %} | {% endif %} {% if DirectPhone == blank %}{% else %}DD: {{DirectPhone}}{% endif %}
    {% if Phone == blank %}{% else %}{{Phone | substr_after: '+1' | phone_format: '000-000-0000'}} (direct)
    {% if ShowDirect == 'True' or ShowDirect == 'true' %}d {{DirectPhone}}{% else %}{% endif %}
  • unless
    Like if, but executes a block of code only if a certain condition is not met (that is, if the result is false).
    {% unless Email | contains: 'xink.io' %} Email does not contain 'xink.io' {% endunless %}
  • case/when
    Creates a switch statement to execute a particular block of code when a variable has a specified value. case initializes the switch statement, and when statements define the various conditions. You can optionally add an else statement at the end of the case to provide code to execute if none of the conditions are met.
    {% case City %}{%when 'Hellerup'%}You're living in Denmark{%when 'Paris'%}France!{%else%}Your city is {{City}}{% endcase %}
    {% case State %}{%when 'California'%}CA {%when 'Florida'%}FL {%when 'Texas'%}TX {%when 'New Jersey'%}NJ {%when 'New York'%}NY {%when 'Ohio'%}OH {%when 'Missouri'%}MO {%when 'Arkansas'%}AR{%else%}{{State}}{% endcase %}
  • for
    Repeatedly executes a block of code 
    {% for entry in fields %} {{forloop.index}}. {{entry[0]}} : {{entry[1]}}{% endfor %} 
  • assign
    Creates a new variable.
    {% assign e = Email %} My email is {{ e }}.
  • capture
    Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created through {% capture %} are strings. Using capture, you can create complex strings using other variables created with assign.
    {% assign n = DisplayName %} {% assign e = Email %} {% capture about_me %} I am {{ n }} and my email is {{ e }}. {% endcapture %} {{ about_me }}
Filters

Filters change the output of a Liquid object. They are used within an output and are separated by a |.

  • substr_before & substr_before_ci
    {{ Email | substr_before: 'xink.io' }}
    {{ Email | substr_before_ci: 'XINK.IO' }}

    Input:

    Output:

  • substr_after & substr_after_ci
    {{ Email | substr_after: '@' }}

    Input:

    Output:

  • append
    Concatenates two strings and returns the concatenated value.
    {{ Email | append: ' some text' }}

    Input:

    Output:

  • prepend
    Adds the specified string to the beginning of another string.
    {{ Email | prepend: ' some text' }}

    Input:

    Output:

  • capitalize
    Makes the first character of a string capitalized.
    {{ Email | capitalize }}

    Input:

    Output:

  • downcase
    Makes each character in a string lowercase. It has no effect on strings which are already all lowercase.
    {{ 'SoMe TeXt' | downcase }}

    Input:

    Output:

  • upcase
    Makes each character in a string uppercase. It has no effect on strings which are already all uppercase.
    {{ 'SoMe TeXt' | upcase }}

    Input:

    Output:

  • remove_first
    Replaces only the first occurrence of the first argument in a string with the second argument.
    {{ 'SoMe TeXt' | replace_first: 'e', 'A' }}

    Input:

    Output:

  • replace
    Replaces every occurrence of an argument in a string with the second argument.
    {{ 'SoMe TeXt' | replace: 'e', 'A' }}

    Input:

    Output:

  • phone_format
    Changes the format of the phone number.
    {{'222 - (222)22' | phone_format: '000-00-00'}}
    {{Phone | phone_format: '+00 0000 0000'}}
    {{Phone | phone_format: '000"."000"."0000'}}

    You can combine several filters together.

    You want to reformat this phone number +1 9083408836 into this one 908 340 8836.

    {{ Phone | substr_after: '+1' | phone_format: '000-000-0000'}} (direct)

    Input:

    Output:

  • minus
    Subtracts a number from another number.
    {{ 15 | minus: 3}}

    Input:

    Output:

  • plus
    Adds a number to another number.
    {{ 15 | plus: 3}}

    Input:

    Output:

  • ceil
    Rounds the input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
    {{ 1.26 | ceil}}

    Input:

    Output:

  • floor
    Rounds a number down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
    {{ 1.26 | floor}}

    Input:

    Output:

  • modulo
    Returns the remainder of a division operation.
    {{ 10 | modulo: 3}}

    Input:

    Output:

  • round
    Rounds an input number to the nearest integer or, if a number is specified as an argument, to that number of decimal places.
    {{ 1.26 | round: 1}}

    Input:

    Output:

  • times
    Multiplies a number by another number.
    {{ 1.26 | times: 5}}

    Input:

    Output:

How to add the liquid in your signature

  1. Open your signature and click 'Source' on the toolbar.
  2. Type '@liquid' at the very top.
  3. Paste your Liquid operator.
  4. Click 'Source' again.
  5. Preview the result.
  6. Click 'OK'.
Use Source to add the Liquid instruction

@liquid must stay at the top of the signature!

Once you are sure that @liquid is at the top of your signature, feel free to embed the appropriate conditional under it in the Source.

Wrap fields in curly braces

In Liquid objects and variable names are denoted by double curly braces - {{Email}}, {{DisplayName}}, {{JobTitle}} etc.

When you select the fields from the Fields drop down list, they will come inside the round brackets by default - ((Email)), ((DisplayName)), ((JobTitle)). But when you use Liquid in your template, make sure you manually replaced the round brackets with the curly braces {{Email}}, {{DisplayName}}, {{JobTitle}}.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.