summaryrefslogtreecommitdiffstats
path: root/docs/content/en/functions/cond.md
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-10-21 10:22:28 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-10-21 10:22:28 +0200
commit27aef3f1fbf657137e825f30bb50dda393618a6f (patch)
treebcc05254f2977e3cc75d7dcb4cbaac5625cf7a1b /docs/content/en/functions/cond.md
parent39121de4d991bdcf5f202da4d8d81a8ac6c149fc (diff)
parentb9bd35d72e14932fb6588ff62b90cddef0a060fc (diff)
Diffstat (limited to 'docs/content/en/functions/cond.md')
-rw-r--r--docs/content/en/functions/cond.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/docs/content/en/functions/cond.md b/docs/content/en/functions/cond.md
new file mode 100644
index 000000000..a5e534426
--- /dev/null
+++ b/docs/content/en/functions/cond.md
@@ -0,0 +1,31 @@
+---
+title: "cond"
+date: 2017-09-08
+description: "Return one of two arguments, depending on the value of a third argument."
+categories: [functions]
+menu:
+ docs:
+ parent: "functions"
+signature: ["cond CONTROL VAR1 VAR2"]
+hugoversion: 0.27
+relatedfuncs: [default]
+toc: false
+draft: false
+needsexamples: 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](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`.
+{{% /warning %}}