diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-01-27 10:47:28 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-01-27 10:47:28 +0100 |
commit | fc7de7136acbcf0aef54ae8460c7702bc83709be (patch) | |
tree | c109bb4dd1f1b054db476e7e4117f79bdd62ec9e /docs/content/en/functions/compare/Conditional.md | |
parent | 1083bf7c08e6f35826279065b8a09a16cc991c7f (diff) | |
download | hugo-fc7de7136acbcf0aef54ae8460c7702bc83709be.tar.gz hugo-fc7de7136acbcf0aef54ae8460c7702bc83709be.zip |
docs: Prepare for new sub tree
See #11925
Diffstat (limited to 'docs/content/en/functions/compare/Conditional.md')
-rw-r--r-- | docs/content/en/functions/compare/Conditional.md | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/docs/content/en/functions/compare/Conditional.md b/docs/content/en/functions/compare/Conditional.md deleted file mode 100644 index 6d693770d..000000000 --- a/docs/content/en/functions/compare/Conditional.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: compare.Conditional -description: Returns one of two arguments depending on the value of the control argument. -categories: [] -keywords: [] -action: - aliases: [cond] - related: - - functions/compare/Default - returnType: any - signatures: [compare.Conditional CONTROL ARG1 ARG2] -aliases: [/functions/cond] ---- - -The CONTROL argument is a boolean value that indicates whether the function should return ARG1 or ARG2. If CONTROL is `true`, the function returns ARG1. Otherwise, the function returns ARG2. - -```go-html-template -{{ $qty := 42 }} -{{ cond (le $qty 3) "few" "many" }} → many -``` - -The CONTROL argument must be either `true` or `false`. To cast a non-boolean value to boolean, pass it through the `not` operator twice. - -```go-html-template -{{ cond (42 | not | not) "truthy" "falsy" }} → truthy -{{ cond ("" | not | not) "truthy" "falsy" }} → falsy -``` - -{{% note %}} -Unlike [ternary operators] in other languages, the `cond` function does not perform [short-circuit evaluation]. The function evaluates both ARG1 and ARG2, regardless of the CONTROL value. - -[short-circuit evaluation]: https://en.wikipedia.org/wiki/Short-circuit_evaluation -[ternary operators]: https://en.wikipedia.org/wiki/Ternary_conditional_operator -{{% /note %}} - -Due to the absence of short-circuit evaluation, these examples throw an error: - -```go-html-template -{{ cond true "true" (div 1 0) }} -{{ cond false (div 1 0) "false" }} -``` |