if
Renders the specified code block if the evaluation result of a specific condition is truthy.
{{#if condition }}
expression
{{/if}}
condition: The condition to evaluate.
Examples
Single condition
The following example compares two values of the same type and renders the specified code block if the specified condition is met.
{{#if product.price > 30 }}
product price more than 30
{{/if}}
Multi-branch logic
The following example compares two values of the same type and renders different code blocks when different conditions are met.
{{#if product.price < 30 }}
product price less than 30
{{#else if product.price > 30 /}}
product price more than 30
{{/if}}
The following example compares two values of the same type and renders different code blocks based on whether the specified condition is met.
{{#if product.price < 30 }}
product price less than 30
{{#else/}}
product price more than 30
{{/if}}
Was this article helpful to you?