Data Types: String Number Boolean Nil Array EmptyDrop in Shopify

When it comes to a website, data is the first thing you come up with. Shopify is built based on Liquid language. Therefore, this tutorial today aims to give you profound introduction to Liquid template and explain types of Liquid data.

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 order assign to announce a string name Hello 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 that if blocks and other Liquid tags that check the truthfulness of statement.

In the example below, unless the user exists (that is, user return nil), 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, this tutorial continues to give you a brief introduction to Liquid template. Liquid has five main types: string, boolean, number, array and nil. Each type assists you in uploading dynamic content on the front page. We hope that you will find something useful in this tutorial.