Skip to main content

Boolean/Bool (true/false)

A bool is a truth value and can only be true or false.
truetruth value true
falsetruth value false
"true"not a truth value (wrong syntax: string)
Boolean values are mostly produced in combination with comparison operators. For example, when comparing one value with another, the result is either true or false.
{{ if $quantity == 1 }}
    Displayed when the value of the variable $quantity equals 1.
{{ /if }}

truthy and falsy

Not only values of the data type bool contain a truth value. Objects of all other data types also have a value property referred to as truthy or falsy. In the context of logical operators and branching, it is important to know when a value is considered true or false. Here is a list of all values that are falsy and are therefore treated as false: null, the value of the Null data type false ▪ the number 0 (Integer) or 0.0 (Float) ▪ an empty string ” ” ▪ an empty list [ ] ▪ an empty map All other values are treated as truthy.

Converting to boolean

Other base types can be converted to boolean:
String: {{= bool(" ")}} // true
String: {{= bool("")}} // false

Integer: {{= bool(1) }} // true
Integer: {{= bool(0) }} // false

Float: {{= bool(1.0) }} // true
Float: {{= bool(0.0) }} // false