Developers · Liquid
Liquid Types
Last updated 2 November 2026
This document details the following topics:
- String
- Boolean
- Number
- Nil
- Hash (Object)
- Array
- Empty
- Truthy and Falsy values
String
Declare a string by wrapping a variable's value in single or double quotes:
{% assign my_string = 'Hello World!' %}A backslash escapes the next character in a string. Put a backslash before a quote to use a quote of the same kind inside a string, for example
Boolean
Booleans are either
{% assign foo = true %}
{% assign bar = false %}Number
Numbers include floats and integers:
{% assign my_int = 25 %}
{% assign my_float = 39.756 %}Nil
Nil is a special empty value that is returned when the Liquid code has no results. It is not a string with the characters 'nil'.
Nil is treated as
In the following example, if the user does not exist (that is, the 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 isHash (Object)
Hash represents an object as a key value dictionary, allowing a value to be another Hash. The most used hash is context, a built-in global object.
Initializing a new object
To create a hash, assign a hash literal. As in JSON, keys are written in double quotes, a key can also be a variable, and literals can be nested. You can also start from an empty hash and set keys with dot or bracket notation:
{% assign my_object = {} %}
{% assign my_object.hello = 'world' %}The parse_json tag and filter are deprecated for JSON you write in the template. Use parse_json only to turn a JSON string that arrives at runtime, such as an API response, into a hash:
Accessing object attributes
To access a value of an object, you can use dot notation or bracket [] notation if you would like to use variables instead of a hardcoded key.
Input
{{ my_object.hello }}
{%- assign var = 'hello' -%}
{{ my_object[var] }}Output
world
worldArray
Arrays hold lists of variables of any type.
Accessing Items in Arrays
You can loop through each item using an iteration tag to access all the items in an array.
Input
{% comment %} if site.users = 'Tobi', 'Laura', 'Tetsuro', 'Adam' {% endcomment %}
{% for user in site.users %}
{{ user }}
{% endfor %}Output
Tobi Laura Tetsuro AdamAccessing Specific Items in an Array
You can use square bracket [ ] notation to access a specific item in an array. Array indexing starts at zero.
Input
{% comment %} if site.users = 'Tobi', 'Laura', 'Tetsuro', 'Adam' {% endcomment %}
{{ site.users[0] }}
{{ site.users[1] }}
{{ site.users[3] }}Output
Tobi
Laura
AdamInitializing Arrays
Create an array with an array literal. Items can be numbers, strings or variables, and [] is an empty array. Append to an existing array with <<, for example
The split filter turns a string into an array of strings.
{% assign arr = [1, 2, 3, 4, 5] %}
{{ arr | join: ', ' }} => 1, 2, 3, 4, 5
{% assign words = 'one,two,three' | split: ',' %}
{{ words.size }} => 3Searching in Arrays
These are the two methods you can use to search arrays
contains
You can check for the presence of a substring in a string, but
{% comment %} site.users = ['Tobi', 'Laura', 'Tetsuro', 'Adam'] {% endcomment %}
{% if site.users contains 'Tobi' %}
Tobi is in users.
{% endif %}array_any
Parameters:
- 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 | array_any: 'Tobi' %}
Tobi is in users.
{% endif %}Empty
An
You can compare an object with
Truthy and Falsy Values
In programming, anything that returns true in a conditional (return true by default) is called truthy. Anything that returns false in a conditional (return false by default) 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
Input
{% if settings.fp_heading %}
<h2>{{ settings.fp_heading }}</h2>
{% endif %}Output
<h2></h2>Falsy
The falsy values in Liquid are nil and false.
Truthy and Falsy Summary Table
| Value | Truthy | Falsy |
|---|---|---|
| true | ||
| false | ||
| nil | ||
| string | ||
| empty string | ||
| 0 | ||
| integer | ||
| float | ||
| array | ||
| empty array | ||
| page | ||
| Empty Drop |