AVADA logo
Published on

How to use liquid case when statement in Shopify

328 words2 min read
  • Name

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 {#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 {#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.

Exclusive Offer: Shopify Deal for PageFly Audience

Start Your Online Business with Shopify 12 Day Free Trial + Pay Only 1$ For Your First Month