Skip to content

Commit

Permalink
Update compare.Conditional documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored Sep 27, 2024
1 parent 4a46d53 commit 4312d49
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions content/en/functions/compare/Conditional.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,17 @@ action:
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.
If CONTROL is truthy the function returns ARG1, otherwise it 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.
Unlike [ternary operators] in other languages, the `compare.Conditional` function does not perform [short-circuit evaluation]. It 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:

Expand Down

0 comments on commit 4312d49

Please sign in to comment.