Home > Shopify Development > Liquid if else/elsif Statements

How to use liquid if else/ elsif statements in Shopify

Sam Nguyen
Sam Updated: January 07, 2024


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

Liquid has been used in Shopify since 2006 and becomes a popular language template for many 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 are control flow with if/else statement.

Exclusive Offer: Get Shopify 33 days for just $1 + The Online Store Starter Kit

Start your 3-day free trial, and enjoy your first month of Shopify for 1$ plus the premium package designed especially for new Shopify merchants!

Start Free Trial

Table of content

General information about Liquid codes and tag types

Liquid codes are classified into objects, tags, and filters. Objects tell Liquid where the content is shown on a page. Double curly braces denote objects and variable names. Filters change a Liquid object’s output. Tags create logic and control flow for a template. Tags begin with two curly braces and percent signs. Tags can be classified into three types: control flow, iteration, and variable assignment.

How to use if else/elsif statement

In control flow, you can use statement of if else, elsif, unless and case to site and show conflicting syntax on your front page.

This tutorial will guide you to use if else/elsif statement. First, If executes a block of codes in case a certain condition is true. For example, you want to add awesome shoes as a title of the product so that buyers can feel the feeling of wearing this pair of shoes.


{% if product.title == 'Awesome Shoes' %}
  These shoes are awesome!
{% endif %}


These shoes are awesome!

Second, Elsif or else adds more condition within an if or unless block. For instance, a client who is not a member of your closed group signs in and you want him/her to know that he/she is a stranger to the thí group, then you use elsif/else to inform.


<!-- If customer.name = 'anonymous' -->
{% if customer.name == 'kevin' %}
  Hey Kevin!
{% elsif customer.name == 'anonymous' %}
  Hey Anonymous!
{% else %}
  Hi Stranger!
{% endif %}


Hey Anonymous!


In conclusion, if/ else statement responds to the logic of your website. You can use this statement to filter those being strange to your secrete group. We hope that you will find ways to build your page and let us know about your difficulties, and we will try to address them.

Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.

Stay in the know

Get special offers on the latest news from AVADA.