if

fun if(condition: Boolean, body: Lambda): Any

Performs a conditional evaluation of content, including the evaluation of body only if the condition is met. The expression is not evaluated if the condition is false.

Conditional statements return the evaluation of the body if the condition is met, nothing otherwise, and can be used for different purposes, both for layout and for logic.

# Shopping list

.var {needapples} {yes}

.if {.needapples}
I need apples.
.row
A

.if {yes}
B

C
.function {safedivide}
numerator denominator:
.if {.denominator::equals {0}}
0
.ifnot {.denominator::equals {0}}
.numerator::divide by:{.denominator}

Return

the evaluation of body if condition is true, nothing otherwise

Parameters

condition

whether the content should be evaluated

body

content to evaluate if condition is verified. Accepts 0 parameters.

Wiki page

Conditional statements