How to use liquid unless loops in Shopify

Since 2006, Liquid has been used in Shopify as a language template. In Liquid, you use tags consisting of comment, control flow, iteration, raw, and variable to show complex content. In this tutorial, we will introduce you about unless statement so that you are able to display special code.

Table of content

A brief introduction to Liquid and tag types

There are three types in Liquid codes including objects, tags, and filters. Liquid use objects to show the location of the content 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 divided into three types: control flow, iteration, and variable assignment.

In control flow, there are five tags that you are able to use to upload dynamic content: if, unless, else, case/when. Today, tutorial guides you to use unless tag.

Let’s move to the next part to see how to display unless tags.

How to show unless tags

unless tags have opposite function with if tags. If tags execute a block of codes in case a certain condition is true while unless tags execute a block of code only if a certain condition is not met.

Look at the example below. In case you want to post a negative sentence which is these shoes are not awesome. In the input code, unless is put between two percent signs and besides product.title. Then you will see the result.

Input


{% unless product.title == 'Awesome Shoes' %}
  These shoes are not awesome.
{% endunless %}

Output


These shoes are not awesome.

The sample code is equivalent to if and endif code. You can write input code in this way without changing the output.


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

Conclusion

In conclusion, the tutorial aims to instruct you to use unless tags in Liquid. Unless tags help to respond to a block of code in case a certain condition is not met. You can use this type of tag to change from an affirmation sentence to a negative sentence. We hope that you will address your problems thanks to our blogs.

Comments for Liquid unless Loops



Subscribe

Stay in the know

Get special offers on the latest news from AVADA.

Earn $10 in reward now!

Earn $10 in reward now!

comment
iphone
go up