compare
compare.Conditional
Conditional can be used as a
ternary operator.
It returns a
if condition
, else b.
Aliases: cond
Examples
{{ cond (eq (add 2 2) 4) "2+2 is 4" "what?" | safeHTML }}
2+2 is 4
compare.Default
(dflt any, given …any) → any
Default checks whether a given
value is set and returns a default value if it
is not. “Set” in this context means non-zero for numeric types and times;
non-zero length for strings, arrays, slices, and maps;
any boolean or struct value; or non-nil for any other types.
Aliases: default
Examples
{{ "Hugo Rocks!" | default "Hugo Rules!" }}
Hugo Rocks!
{{ "" | default "Hugo Rules!" }}
Hugo Rules!
compare.Eq
(first any, others …any) → bool
Eq returns the boolean truth of arg1 == arg2 || arg1 == arg3 || arg1 == arg4.
Aliases: eq
Examples
{{ if eq .Section "blog" }}current-section{{ end }}
current-section
compare.Ge
(first any, others …any) → bool
Ge returns the boolean truth of arg1 >= arg2 && arg1 >= arg3 && arg1 >= arg4.
Aliases: ge
Examples
{{ if ge hugo.Version "0.80" }}Reasonable new Hugo version!{{ end }}
Reasonable new Hugo version!
compare.Gt
(first any, others …any) → bool
Gt returns the boolean truth of arg1 > arg2 && arg1 > arg3 && arg1 > arg4.
Aliases: gt
compare.Le
(first any, others …any) → bool
Le returns the boolean truth of arg1 <= arg2 && arg1 <= arg3 && arg1 <= arg4.
Aliases: le
compare.Lt
(first any, others …any) → bool
Lt returns the boolean truth of arg1 < arg2 && arg1 < arg3 && arg1 < arg4.
Aliases: lt
compare.Ne
(first any, others …any) → bool
Ne returns the boolean truth of arg1 != arg2 && arg1 != arg3 && arg1 != arg4.
Aliases: ne