github.com/rabbouni145/gg@v0.47.1/docs/content/en/functions/cond.md (about) 1 --- 2 title: "cond" 3 date: 2017-09-08 4 description: "Return one of two arguments, depending on the value of a third argument." 5 categories: [functions] 6 menu: 7 docs: 8 parent: "functions" 9 signature: ["cond CONTROL VAR1 VAR2"] 10 hugoversion: 0.27 11 relatedfuncs: [default] 12 toc: false 13 draft: false 14 needsexamples: false 15 --- 16 17 `cond` returns *VAR1* if *CONTROL* is true, or *VAR2* if it is not. 18 19 Example: 20 21 ``` 22 {{ cond (eq (len $geese) 1) "goose" "geese" }} 23 ``` 24 25 Would emit "goose" if the `$geese` array has exactly 1 item, or "geese" otherwise. 26 27 {{% warning %}} 28 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*. 29 30 In other words, the `cond` function does *not* provide [short-circuit evaluation](https://en.wikipedia.org/wiki/Short-circuit_evaluation) and does *not* work like a normal [ternary operator](https://en.wikipedia.org/wiki/%3F:) that will pass over the first expression if the condition returns `false`. 31 {{% /warning %}}