Data Types: String Number Boolean Nil Array EmptyDrop in Shopify
- Overall about Liquid templateTypes of Liquid
- String
In the ecommerce industry, Liquid stands out as a powerful and indispensable tool enabling developers to create dynamic, customizable content tailored to specific customer needs. Shopify has chosen Liquid as its foundation language, allowing merchants to integrate static and dynamic content across their stores. This guide provides a deep dive into Liquid’s data types, explain their structure, usage, and the crucial role each type plays in building a professional, and effective Shopify website.
Table of content
Overall about Liquid template
A language template is a website language that web designers use to build website combined with static content and dynamic content. The former is the same on multiple pages and the later changes from one page to the next. Liquid is a template language that Shopify uses.
Liquid is now available as an open source project on GitHub and used by a lot of websites and companies. Liquid is suitable for uploading dynamic content on websites.
Types of Liquid
Liquid has five main types: String, Number, Boolean, Nil and Array. Each type will be presented in the next parts.
String
In Liquid template, you declare a string by grouping variable’s value in single or double quotes. For example, you insert
my_string
after a call orderassign
to announce a string nameHello World
.{% assign my_string = "Hello World!" %}
Number
Number allows you to add numbers or integers in the code. For instance, you include the size of int.
{% assign my_int = 25 %} {% assign my_float = 39.756 %}
Boolean
Boolean in a Liquid type that give answer to true or false. There is no quotations when you declare a boolean.
{% assign foo = true %} {% assign bar = false %}
Nil
Nil is the most special type of Liquid language. Nil is an empty value which is returned when Liquid code has no result.
Nil gives
false
result in case thatif
blocks and other Liquid tags that check the truthfulness of statement.In the example below, unless the user exists (that is,
user
returnnil
), Liquid will not print the greeting:{% if user %} Hello {{ user.name }}! {% endif %}
Tags or outputs that return
nil
will not be displayed on the front page.Input
The current user is {{ user.name }}
Output
The current user is
Array
Array is used the most in Liquid language template. Array can hold lists of variables of any type. You can access any items or specific items in array.
Accessing items in array
You go through each item in the array using an iteration tag which runs blocks of code repeatedly such as
for
,cycle
,tablerow
to access all items in an array.Input
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" --> {% for user in site.users %} {{ user }} {% endfor %}
Output
Tobi Laura Tetsuro Adam
In order to access a specific item, you use square bracket notation.
Input
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" --> {{ site.users[0] }} {{ site.users[1] }} {{ site.users[3] }}
Output
Tobi Laura Adam
Conclusion
In a nutshell, Liquid is more than just a programming language; it’s a powerful asset that transforms e-commerce websites into engaging, customer-centric platforms. From Strings and Numbers to Booleans, Nil values, and Arrays, each data type in Liquid contributes to a seamless, modern, and professional web experience. We hope this tutorial has equipped you with the knowledge to master Liquid, create impressive dynamic content, and unlock the full potential of Shopify for your online store.
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.Related Post