mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-02 08:30:07 +03:00
1.4 KiB
1.4 KiB
title | description | keywords | params | aliases | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
compare.Default | Returns the second argument if set, else the first argument. |
|
|
The default
function returns the second argument if set, else the first argument.
Note
When the second argument is the boolean
false
value, thedefault
function returnsfalse
. All other falsy values are considered unset.The falsy values are
false
,0
, anynil
pointer or interface value, any array, slice, map, or string of length zero, and zerotime.Time
values.Everything else is truthy.
To set a default value based on truthiness, use the
or
operator instead.
The default
function returns the second argument if set:
{{ default 42 1 }} → 1
{{ default 42 "foo" }} → foo
{{ default 42 (dict "k" "v") }} → map[k:v]
{{ default 42 (slice "a" "b") }} → [a b]
{{ default 42 true }} → true
<!-- As noted above, the boolean "false" is considered set -->
{{ default 42 false }} → false
The default
function returns the first argument if the second argument is not set:
{{ default 42 0 }} → 42
{{ default 42 "" }} → 42
{{ default 42 dict }} → 42
{{ default 42 slice }} → 42
{{ default 42 <nil> }} → 42