Handlebar Helper Function: IIf

Evaluates an expression and returns one of two values based on whether the expression is true or false. This function works similarly to a ternary operator in other programming languages.

ParameterTypeDescription
expressionanyRequired. The expression to evaluate.
leftResultanyRequired. The value to return if the expression evaluates to true.
rightResultanyRequired. The value to return if the expression evaluates to false.

The function returns leftResult if the expression evaluates to true according to truthiness rules, otherwise returns rightResult. Truthiness evaluation follows these rules: null is false; boolean values are returned as-is; 0 is false, any non-zero number is true; empty string "" is false, any non-empty string is true; empty arrays [] and empty objects {} are false. Both leftResult and rightResult are always evaluated, regardless of which is returned.