compare.Conditional
Returns one of two arguments depending on the value of the control argument.
- Syntax
- compare.Conditional CONTROL ARG1 ARG2
- Returns
- any
- Alias
- cond
If CONTROL is truthy the function returns ARG1, otherwise it returns ARG2.
{{ $qty := 42 }}
{{ cond (le $qty 3) "few" "many" }} → manyUnlike 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.
Due to the absence of short-circuit evaluation, these examples throw an error:
{{ cond true "true" (div 1 0) }}
{{ cond false (div 1 0) "false" }}Last updated:
June 18, 2026
:
Merge commit 'c86d9f4aa8a58931f52df6516f10b67c807505fb' (be780afa7)
Improve this page