hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

cond.md (1086B)

    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 ---
   15 
   16 `cond` returns *VAR1* if *CONTROL* is true, or *VAR2* if it is not.
   17 
   18 Example:
   19 
   20 ```
   21 {{ cond (eq (len $geese) 1) "goose" "geese" }}
   22 ```
   23 
   24 Would emit "goose" if the `$geese` array has exactly 1 item, or "geese" otherwise.
   25 
   26 {{% warning %}}
   27 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*.
   28 
   29 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`.
   30 {{% /warning %}}