How to use liquid case when statement in Shopify

Liquid has become a backbone of Shopify since 2006 with a lot of good reviews from website application. Liquid provides you with three main sources to upload the dynamic content on your front page, hence today tutorial will dig into one of the most noticeable features which is control flow with case/when statement.

Table of content

General information about Liquid codes and tag types

Liquid codes are divided into objects, tags and filters. Double curly braces denote objects and variable names. Filters change a Liquid object’s output. There are five main types of filters including string, number, boolean, nil and array. Tags create logic and control flow for a template. Tags begin with two curly braces and percent signs. Tags is classified into control flow, iteration and variable assignment.

This tutorial focuses on control flow function by guiding you to use case/when statements.

How to use case when statement

Case/when statements create a switch statement to compare a variable with different values. In fact, case starts with switching statement and when compares its values. Your web will show the text or letter that you write in the first line of your code, if the input sentence is not valid, the web will not show.


{% assign handle = 'cake' %}
{% case handle %}
  {% when 'cake' %}
     This is a cake
  {% when 'cookie' %}
     This is a cookie
  {% else %}
     This is not a cake nor a cookie
{% endcase %}


This is a cake


To sum up, the tutorial aims to guide you to use case/when statements. Case/when statements allows you to display right content if you insert characters which are the same as the initial ones. We hope that our article is helpful to you. Let’s us know your difficulties and we will address them.

Recommend for you
Image Description
SEO Suite [FREE]

Auto-optimize website elements and structure in one-click.

Learn more
Proofo - Social Proof [FREE]

Use Social proof to boost sales

Learn more
Image Description
Size Chart [FREE]

Stunning size guide for great shopping experience

Learn more
Image Description
Free Shipping Bar [FREE]

Increase customers’ shopping cart size with free shipping offer

Learn more

Comments for Liquid case when statement


Stay in the know

Get special offers on the latest news from AVADA.

40k subscribers has been joined!

Earn $10 in reward now!

go up