For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 }}
Parameter
Description

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, 0 and "" become false (case-insensitive, surrounding whitespace ignored)

  • true, t, yes, y, on and 1 become true

  • Any other non-empty string is true, matching Liquid's own truthiness

  • Numbers follow the usual rule: 0 is false, everything else is true

  • nil and undefined are false; arrays and objects are true, including empty ones

  • See also: integer, is_number, type

Last updated