if
Renders an expression if a specific condition is true
.
Syntax
{% if condition %}
expression
{% endif %}
condition
The condition to evaluate.
expression
The expression to render if the condition is met.
{% if product.compare_at_price > product.price %}
This product is on sale!
{% endif %}
{% if product.compare_at_price > product.price %}
This product is on sale!
{% endif %}
{
"product": {
"compare_at_price": "10.00",
"price": "0.00"
}
}
Output
This product is on sale!
Anchor to elsif
elsif
You can use the elsif
tag to check for multiple conditions.
{% if product.type == 'Love' %}
This is a love potion!
{% elsif product.type == 'Health' %}
This is a health potion!
{% endif %}
{% if product.type == 'Love' %}
This is a love potion!
{% elsif product.type == 'Health' %}
This is a health potion!
{% endif %}
{
"product": {
"type": null
}
}
Output
This is a health potion!
Was this page helpful?