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 %}
Code
{% if product.compare_at_price > product.price %}
This product is on sale!
{% endif %}Data
{
"product": {
"compare_at_price": "10.00",
"price": "0.00"
}
}Output
This product is on sale!
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 %}
Code
{% if product.type == 'Love' %}
This is a love potion!
{% elsif product.type == 'Health' %}
This is a health potion!
{% endif %}Data
{
"product": {
"type": null
}
}Output
This is a health potion!
Output
This is a health potion!Was this page helpful?