Liquid Types

Last updated on June 18, 2024

This document details the following topics:

  • string
  • boolean
  • number
  • nil
  • array
  • empty
  • truthy and falsy values

string

Declare a string by wrapping a variable's value in single or double quotes:

Liquid does not convert escape sequences into special characters.

boolean

Booleans are either or . No quotations are necessary when declaring a boolean:

number

Numbers include floats and integers:

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 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, the user returns nil), Liquid will not print the greeting:

Tags or outputs that return nil will not print anything to the page.

Input

Output

array

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

Output

Accessing 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

Output

Initialising Arrays

You cannot initialise arrays using only Liquid.

You can, however, use the split filter to break a string into an array of substrings.

Searching 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 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.

any

Parameters:

  • array (Array) - array to search in - default: []
  • query (StringNumber) - String/Number compared to each item in the given array - default: 'true'

empty

An object is returned if you try to access an object that is defined but has no value. For example, a page or product deleted or a setting with no value.

You can compare an object with to check whether an object exists before you access any of its attributes.

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:

Strings, even when empty, are truthy. The example below will result in empty HTML tags if is empty.

Input

Output

Falsy

The falsy values in Liquid are nil and false.

Truthy and Falsy Summary Table

ValueTruthyFalsy
true
false
nil
string
empty string
0
integer
float
array
empty array
page
Empty Drop
Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.