How to use liquid case when statement in Shopify

Updated: July 08, 2021

Share:

Drive 20-40% of your revenue with
email, SMS marketing
avada email marketing

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.

Input


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

Output


This is a cake

Conclusion

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
SMS, Email Marketing Automation

Top rated Marketing automation for Shopify stores

Learn more
Image Description
SEO Suite

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

Learn more
proofo
Boost Sales [Free]

Boost sales: Sales Pop, Trust badges, Countdown timer, more

Learn more
Image Description
Photo Reviews [Free]

Use photo reviews to boost sales

Learn more

Subscribe

Stay in the know

Get special offers on the latest news from AVADA.

40k subscribers has been joined!

Earn $10 in reward now!

comment
iphone
go up