Skip to main content

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 %}

Output

This product is on sale!

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 %}

Output

This is a health potion!
Was this page helpful?