boolean
Casts a value to true or false, recognizing the textual booleans that CSV files, metafields and form fields carry.
{% assign active = row.active | boolean %}Syntax
{{ value | boolean }}value
Any value to convert to a boolean
Return Value
Returns true or false.
Examples
Read a flag from a CSV column:
{% assign rows = file.content | parse_csv %}
{% for row in rows %}
{% if row.discontinued | boolean %}
{% assign to_archive = to_archive | push: row.sku %}
{% endif %}
{% endfor %}Without the cast, {% if row.discontinued %} is true for the string "false" — any non-empty string is truthy in Liquid.
Normalize a metafield before writing it back:
Notes
false,f,no,n,off,0and""becomefalse(case-insensitive, surrounding whitespace ignored)true,t,yes,y,onand1becometrueAny other non-empty string is
true, matching Liquid's own truthinessNumbers follow the usual rule:
0isfalse, everything else istrueniland undefined arefalse; arrays and objects aretrue, including empty onesSee also:
integer,is_number,type
Last updated