Liquid Tutorial

Liquid Case

Source: Coding with Robby

Multi-Way Branching with case

When a single variable has many known values, {% case %} is cleaner than a long elsif chain. Liquid compares the variable to each {% when %} value and executes the first match.

Product type messaging
{% case product.type %}
  {% when 'Digital Course' %}
    <span class="icon">📚</span>
    <span>Instant digital access after purchase</span>
  {% when 'Course Bundle' %}
    <span class="icon">📦</span>
    <span>Includes multiple courses</span>
  {% when 'Coaching Session' %}
    <span class="icon">🎯</span>
    <span>Book a 1-on-1 session after checkout</span>
  {% else %}
    <span class="icon">🛒</span>
    <span>Standard product</span>
{% endcase %}

product.type is a free-text field merchants set in Admin. Document expected values in your theme's merchant documentation. For more structured data, prefer metafields over product.type.

Tip: case only supports exact matches — not ranges or contains. Use if/elsif for complex conditions.