/

August 5, 2024

Conditional Statements For Shopify Liquid Code

What is the condition? and what are the types of conditions in Shopify?

The condition means it is either true or false.

There are many types of conditions or decision-making in Shopify

1) IF condition.

2) IF ELSE condition.

3) NESTED IF condition

4) ELSE IF LADDER condition.

let’s show you one by one in this blog.

 

1) if Condition.

Liquid code Example

In the above syntax, the statement block may be a single statement or a group of statements.

The simple if statement is executed in the following order.

first, the condition is checked.

if the condition is proper then the statement block is executed

 

2) if-else Condition.

Liquid code Example.

The if..else statement is executed in the following order:

first, the condition is checked.

if the condition is actual then true statement 1 is executed.

if the condition is false then false statement 2 is executed.

 

3) else if ladder Condition.

Remember it’s an else if statement, not an else if statement if you write this then Liquid throws an error.

Liquid code Example.

The nesting elsif statement is executed in the following manner.

First, condition 1 is checked.

if condition 1 is actual then condition 2 is checked. If condition 2 is actual then statement-1 is executed.

but if condition 2 is false statement-2 is performed.

if condition 1 is false statement-3 is executed.

From the same category