Types
Liquid objects can be one of six types:
You can initialize Liquid variables using assign
or capture
tags.
String
Strings are sequences of characters wrapped in single or double quotes:
Liquid does not convert escape sequences into special characters.
Number
Numbers include floats and integers:
Boolean
Booleans are either true
or false
. No quotations are necessary when declaring a boolean:
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:
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
To access all the items in an array, you can loop through each item in the array using an iteration tag.
Input
Output
Accessing specific items in arrays
You can use square bracket [
]
notation to access a specific item in an array. Array indexing starts at zero. A negative index will count from the end of the array.
Input
Output
Initializing arrays
You cannot initialize arrays using only Liquid.
You can, however, use the split
filter to break a string into an array of substrings.
EmptyDrop
An EmptyDrop object is returned if you try to access a deleted object. In the example below, page_1
, page_2
and page_3
are all EmptyDrop objects:
Checking for emptiness
You can check to see if an object exists or not before you access any of its attributes.
Both empty strings and empty arrays will return true
if checked for equivalence with empty
.
Last updated