mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-12 04:24:13 +00:00
5a72de2600
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
967 B
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 |
|
|
|
|
|
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
.