hugo/docs/content/en/functions/bool.md
Khayyam Saleem 5a72de2600 tpl: adds truth and bool template functions
The behavior of `truth` and `bool` is described in the corresponding
test cases and examples. The decision-making around the behavior is a
based on combination of the existing behavior of strconv.ParseBool in go
and the MDN definition of "truthy" as JavaScript has the most interop
with the Hugo ecosystem.

Addresses #9160 and (indirectly) #5792
2023-10-17 23:52:33 -04:00

967 B

title linktitle description date publishdate lastmod categories menu keywords signature workson hugoversion relatedfuncs deprecated aliases
bool bool Creates a `bool` from the argument passed into the function. 2023-01-28 2023-01-28 2023-01-28
functions
docs
parent
functions
strings
boolean
bool
bool INPUT
truth
false

Useful for turning ints, strings, and nil into booleans.

{{ bool "true" }} → true
{{ bool "false" }} → false

{{ bool "TRUE" }} → true
{{ bool "FALSE" }} → false

{{ truth "t" }} → true
{{ truth "f" }} → false

{{ truth "T" }} → true
{{ truth "F" }} → false

{{ bool "1" }} → true
{{ bool "0" }} → false

{{ bool 1 }} → true
{{ bool 0 }} → false

{{ bool true }} → true
{{ bool false }} → false

{{ bool nil }} → false

This function will throw a type-casting error for most other types or strings. For less strict behavior, see truth.