Liquid - Introduction

Last edit: Jun 10, 2019
  • Contributors:
  • pavelloz

Liquid is a template language used in platformOS to build dynamic pages, and to provide dynamic configuration (e.g. based on currently logged in user).
Use Liquid to provide an authorization policy for forms and pages, or to specify notifications (email, SMS, API call). We have added a lot of filters and tags to make your life easier.

Output

Output markup (which may resolve to text) is surrounded by


{{ matched pairs of curly brackets (ie, braces) }}

Example


{{ user.name }} => John

Tags

Tag markup (which cannot resolve to text) is surrounded by


{% matched pairs of curly brackets and percent signs %}

Example


{% if user %}
  true
{% endif %}

Filters

Liquid filters are simple methods that modify the output of numbers, strings, variables, and objects.

Simple use case


{{ "honda crx" | upcase }} => HONDA CRX

Arguments

Some filters accept arguments, for example, the replace filter accepts two:


{{ 'Hello liquid' | replace: 'liquid', 'world!' }} => Hello world!

Chaining

Having a verbose version of code that will:

  1. Create string with words
  2. Prepend "Zero," in front of the string
  3. Append ",Five" string at the end
  4. Split it by comma to create an array of strings
  5. Print it to the source

{% assign numbers = 'One,Two,Three,Four' %}
{% assign numbersWithZero = 'One,Two,Three,Four' | prepend: 'Zero,' %}
{% assign all_numbers = numbersWithZero | append: ',Five' %}
{% assign all_numbers_array = all_numbers | split: ',' %}
{{ all_numbers_array }} => ZeroOneTwoThreeFourFive

You can achieve the same result in much shorter form by chaining the filters one after another:


{{ 'One,Two,Three,Four' | prepend: 'Zero,' | append: ',Five' | split: ',' }} => ZeroOneTwoThreeFourFive

Raw

If you want to use liquid text on your page but without executing it, use {% raw %} ... {% endraw %} syntax.

Comment

Allows you to leave un-rendered code inside a Liquid template. Any text within the opening and closing comment blocks will not be output, and any Liquid code within will not be executed.

Input


Anything you put between {% comment %} and {% endcomment %} tags
is turned into a comment.

Output

Anything you put between  tags
is turned into a comment.

Questions?

We are always happy to help with any questions you may have.