Truthy and falsy
Last updated
Last updated
When a non-boolean is used in a boolean context (such as a conditional tag), Liquid decides whether to evaluate it as true
or false
. Data types that return true
by default are called truthy. Data types that return false by default are called falsy.
All values in Liquid are truthy except nil
and false
.
In the example below, the text “Tobi” is not a boolean, but it is truthy in a conditional:
, even when empty, are truthy. The example below will create empty HTML tags if category
exists but is empty:
Input
Output
The only values that are falsy in Liquid are nil
and false
.
The table below summarizes what is truthy or falsy in Liquid.
true
•
false
•
nil
•
string
•
empty string
•
0
•
integer
•
float
•
array
•
empty array
•
page
•
EmptyDrop
•