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
Usage
The compare.Conditional function returns one of two arguments depending on the value of the control argument. If CONTROL is truthy the function returns ARG1, otherwise it returns ARG2.
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.
Examples
{{ $qty := 42 }}
{{ compare.Conditional (compare.Le $qty 3) "few" "many" }} → manyDue to the absence of short-circuit evaluation, these examples throw an error:
{{ compare.Conditional true "true" (div 1 0) }}
{{ compare.Conditional false (div 1 0) "false" }}Last updated:
September 16, 2026
:
content: Draft standard for function and method pages (9a554d1fe)
Improve this page