Liquid - Types
String
Declare a string by wrapping a variable's value in single or double quotes:
{% assign my_string = "Hello World!" %}
String interpolation
Note
This feature requires the string_interpolation: true flag in config.yml. See Single vs double quotes for details.
Double-quoted strings support interpolation using the {{ }} syntax. This lets you embed variables, property access, and filters directly inside strings:
Input
{% assign name = "Alice" %}
{% assign greeting = "Hello {{ name }}!" %}
{{ greeting }}
Output
Hello Alice!
Interpolation supports filter chains, multiple expressions, and all variable access patterns:
{% assign first = "Alice" %}
{% assign last = "Smith" %}
{% assign full_name = "{{ first }} {{ last | upcase }}" %}
{{ full_name }}
Output
Alice SMITH
String interpolation works in all tags that accept string values — assign, function, log, background, export, and others:
{% assign var = "world" %}
{% log "hello {{ var }}" %}
{% function res = "lib/func", arg: "hello {{ var }}" %}
Single vs double quotes
Single-quoted strings never interpolate. Use single quotes when you need literal {{ }} text:
{% assign name = "Alice" %}
{% assign interpolated = "Hello {{ name }}" %}
{% assign literal = 'Hello {{ name }}' %}
{{ interpolated }}
{{ literal }}
Output
Hello Alice
Hello
Note
String interpolation is enabled by default on new instances. On existing instances it must be enabled explicitly by adding string_interpolation: true to your config.yml, as it can potentially break your site — any double-quoted strings containing literal {{ }} text will start being interpolated.
Number
Numbers include floats and integers:
{% assign my_int = 25 %}
{% assign my_float = 39.756 %}
Boolean
Booleans are either true or false. No quotations are necessary when declaring a boolean:
{% assign foo = true %}
{% assign bar = false %}
Nil
Nil is a special empty value that is returned when Liquid code has no results. It is not a string with the characters nil.
Nil is treated as false in the conditions of if blocks and other Liquid tags that check the truthfulness of a statement.
In the following example, if the user does not exist (that is, user returns nil), Liquid will not print the greeting:
{% if user %}
Hello {{ user.name }}!
{% endif %}
Tags or outputs that return nil will not print anything to the page.
Input
The current user is {{ user.name }}
Output
The current user is
Hash (Object)
Hash represents an object as a key value dictionary, allowing a value to be another Hash. The most used object is context - a built-in global object
Initializing a new object
Use the assign tag with a hash literal:
{% assign my_object = { "hello": "world" } %}
You can include nested hashes, arrays, and variables as values:
{% assign name = "Alice" %}
{% assign my_object = { "greeting": "hello", "user": name, "tags": ["admin", "editor"] } %}
Accessing object attributes
To access a value of an object, you can use dot notation or if you would like to use variables instead of hardcoded key, you could use [] notation.
Input
{{ my_object.hello }}
{%- assign var = 'hello' -%}
{{ my_object[val] }}
Output
world
world
Working with an object
You can extend objects using the assign tag with bracket or dot notation:
{% assign my_object = {} %}
{% assign my_object["new_key"] = "value" %}
{% assign my_object.another_key = "another value" %}
Another useful way to extend an object is by merging two objects, which can be accomplished with hash_merge filter.
If you need to perform certain operation on object, most likely there is already implemented platformOS filter for that with hash_ prefix.
Array
Arrays hold lists of variables of any type.
Accessing items in arrays
To access all the items in an array, you can loop through each item in the array using an iteration tag.
Input
{% assign users = ["Tobi", "Laura", "Tetsuro", "Adam"] %}
{% for user in users %}
{{ user }}
{% endfor %}
Output
Tobi Laura Tetsuro Adam
Accessing specific items in arrays
You can use square bracket [ ] notation to access a specific item in an array. Array indexing starts at zero.
Input
{% assign site = { "users": ["Tobi", "Laura", "Tetsuro", "Adam"] } %}
{{ site.users[0] }}
{{ site.users[1] }}
{{ site.users[3] }}
Output
Tobi
Laura
Adam
Initializing arrays
Use the assign tag with an array literal:
{% assign arr = ["apple", "banana", "cherry"] %}
{% assign empty_arr = [] %}
You can also use the split filter to break a string into an array of substrings:
{% assign arr = '1,2,3,4,5' | split: ',' %}
{{ arr }} => [1, 2, 3, 4, 5]
To append elements, use the << operator:
{% assign arr = [] %}
{% assign arr << "first" %}
{% assign arr << "second" %}
{{ arr }} => ["first", "second"]
Searching in arrays
contains
You can check for the presence of a substring in a string, but contains can also check for the presence of a string in an array of strings. You can use it only for searching strings. You cannot use it to check for an object in an array of objects.
{% comment %} site.users = ["Tobi", "Laura", "Tetsuro", "Adam"] {% endcomment %}
{% if site.users contains 'Tobi' %}
Tobi is in users.
{% endif %}
any
You can check if the given array contains at least one of the queried string/number.
params
- array (Array) - array to search in - default: []
- query (StringNumber) - String/Number compared to each item in the given array - default: 'true'
{% comment %} site.users = ["Tobi", "Laura", "Tetsuro", "Adam"] {% endcomment %}
{% if site.users | any: 'Tobi' %}
Tobi is in users.
{% endif %}
Truthy and falsy values
In programming, anything that returns true in a conditional is called truthy. Anything that returns false in a conditional is called falsy. All object types can be described as either truthy or falsy.
Truthy
All values in Liquid are truthy except nil and false.
In the example below, the string “Tobi” is not a boolean, but it is truthy in a conditional:
{% assign tobi = "Tobi" %}
{% if tobi %}
This condition will always be true.
{% endif %}
Strings, even when empty, are truthy. The example below will result in empty HTML tags if settings.fp_heading is empty:
Input
{% if settings.fp_heading %}
<h1>{{ settings.fp_heading }}</h1>
{% endif %}
Output
<h1></h1>
Falsy
The falsy values in Liquid are nil and false.
Truthiness summary table
Liquid expressions are tested for "truthiness" in a Ruby-like way:
| truthy | falsy | |
|---|---|---|
| true | • | |
| false | • | |
| nil | • | |
| string | • | |
| empty string | • | |
| 0 | • | |
| integer | • | |
| float | • | |
| array | • | |
| empty array | • | |
| page | • | |
| EmptyDrop | • |
Note
This topic is a compilation of knowledge found at: Shopify Themes, Liquid Documentation, Liquid Gem Documentation, and Liquid for Designers.