hugo/content/en/functions/cond.md
Bjørn Erik Pedersen 3a44bf182f Squashed 'docs/' changes from 81847981f..d88477eb3
d88477eb3 Fix some more redirect alias loops
209735670 Update features.md
d4ec6ef87 Remove redirect loop from functions/default
ce14da435 Fix the AlternativeOutputFormats/OutputFormats examples
f64a22469 Update cond.md
357a70a32 Remove redirect loop from templates/404
4ad7b01ba Remove some aliases that were causing infinite redirect loops
fd378e66a Fix alias redirect loop
ec3629f6f Revert "Set code background to white"
ffc56b880 Revert "Make inline code gray"
2a964e261 Make inline code gray
44069e09c Set code background to white
d39c790d0 Linked my own blog2md migration script
3e55267be Release 0.46
7b6cfdd8b releaser: Prepare repository for 0.47-DEV
d4cb54806 releaser: Add release notes to /docs for release of 0.46
6518ac7e7 releaser: Bump versions for release of 0.46
e54334d5c Merge commit '766085c2dc6fc95ac30fda2a9ebde2355fc12554'

git-subtree-dir: docs
git-subtree-split: d88477eb3a1959e2764d6025f5aa7a57a4a611e7
2018-08-08 13:54:28 +02:00

1.1 KiB

title date description categories menu signature hugoversion relatedfuncs toc draft needsexamples
cond 2017-09-08 Return one of two arguments, depending on the value of a third argument.
functions
docs
parent
functions
cond CONTROL VAR1 VAR2
0.27
default
false false false

cond returns VAR1 if CONTROL is true, or VAR2 if it is not.

Example:

{{ cond (eq (len $geese) 1) "goose" "geese" }}

Would emit "goose" if the $geese array has exactly 1 item, or "geese" otherwise.

{{% warning %}} Whenever you use a cond function, both variable expressions are always evaluated. This means that a usage like cond false (div 1 0) 27 will throw an error because div 1 0 will be evaluated even though the condition is false.

In other words, the cond function does not provide short-circuit evaluation and does not work like a normal ternary operator that will pass over the first expression if the condition returns false. {{% /warning %}}