Welcome to CodeCrew Infotech
If you want to store a single value then you can assign that value to a variable but if want to store many values with the same type that time used Array.
The array uses the same data type value with a common name.
Let's go over the different liquid tags we'll use to create our array.
In this example {{my_variable}} will be the string that is set in the capture.
Output:
Codecrew infotech
Output:
in this example variable name is my_variable and the output of the variable is: Codecrew
which is used in comma-separated items
The above will print a list of cities you like from the cities array.
Using for loop Repeatedly executes a block of code.
Generally when you are using an array values are allocated using for loop.
As an example let's make an array that captures all of the products on a collections page and stores the title, URL, description, and featured image
The code will look something like this:
Here we start with the capture tag where create a product array so we set the product_list variable and assign them to all the product information. When capturing the values we separate each value associated with a single product using a | and each set of production values with::. The:: are included in a conditional statement that checks if the iteration of the for loop is the last and is only appended if it is not the last iteration. We will use both of these characters later to split the data into arrays.
When the products_list variable is complete, create a new variable using the assign tag and store an array of all your products and their respective info by splitting on the::
There are many of forloop object like forloop.first, forloop.last, forloop.index, forloop.index0, forloop.rindex0, forloop.rindex, forloop.length.
We will discuss in detail all objects in the next blog.