if
Render the content within the expression if a condition is true
.
content
condition
Evaluable expression.
content
The render content when the condition is met.
else if
You can use the else if
tag to check multiple conditions.
content
content
{{#if product.type == 'Red' }}
This is a red option!
{{else if product.type == 'Yellow' }}
This is a yellow option!
{{/if}}
else
Allows you to specify a default expression to be executed when none of the other conditions are met.
{{#if product.available }}
This product is available!
{{else}}
This product is sold out!
{{/if}}
Using Subexpressions in if Statements
Handlebars natively supports subexpression, allowing you to write complex conditional statements by invoking other helpers within an if statement.
Using and, or in if Statements
Allows you to evaluate multiple conditions using logical and
and or
operators.
Was this article helpful to you?
Error loading component.