HUGO
Menu
GitHub 90553 stars Mastodon

or

Returns the first truthy argument. If all arguments are falsy, returns the last argument.
Syntax
or VALUE...
Returns
any

Usage

The or function returns the first truthy argument. If all arguments are falsy, it returns the last argument. The function evaluates the arguments from left to right, and stops when the result is determined.

The falsy values are false, 0, any nil pointer or interface value, any array, slice, map, or string of length zero, and zero time.Time values.

Everything else is truthy.

See Go’s text/template documentation for more information.

Examples

{{ or 0 1 2 }} → 1 (int)
{{ or false "a" 1 }} → a (string)
{{ or 0 true "a" }} → true (bool)

When all arguments are falsy:

{{ or false "" 0 }} → 0 (int)
{{ or 0 "" false }} → false (bool)

Stopping before the division by zero is evaluated:

{{ or true (div 1 0) }} → true (bool)