hugo/docs/content/en/functions/truth.md
ksaleem 28434238db tpl: updates cast.ToTruth to conform to hreflect.IsTruthful
Concession from review, where cast.ToTruth should behave exactly like hreflect.IsTruthful.
Additionally, cast.ToBool always returns a bool with nil error.
2023-10-20 09:13:00 -04:00

1.1 KiB

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

Useful for turning different types into booleans based on their truthy-ness.

{{ truth "true" }} → true
{{ truth "false" }} → true

{{ truth "TRUE" }} → true
{{ truth "FALSE" }} → true

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

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

{{ truth "1" }} → true
{{ truth "0" }} → true

{{ truth 1 }} → true
{{ truth 0 }} → false

{{ truth true }} → true
{{ truth false }} → false

{{ truth nil }} → false

{{ truth "cheese" }} → true
{{ truth 1.67 }} → true

This function will not throw an error. For more strict behavior, see bool.