Home > Shopify Development > Liquid map How to Use map

How to Use map in Shopify

Sam Nguyen
Sam Updated: April 21, 2024

Share:

Drive 20-40% of your revenue with Avada
avada email marketing

Using map value in online shopping has been popular today. If you are using Liquid template language, you can take a look to view these steps below to help you use the map in liquid. The tutorial aims to assist you in showing the map on your product page.

Table of content

General knowledge about Liquid template language

The liquid is one of the open-source template languages in Shopify. The liquid is used as the backbone of Shopify to upload dynamic content on the front page. Liquid has been sold since 2006 and now become a good source for a lot of hosted website application such as Jekyll, salesforce desk, and zendesk.

Essential things about the array filter and map in liquid

Array filter is a function used to create a new array from a provided array including names or items which meet the demand of the condition set by the argument function. In general, the formation of an array looks like this:

sample array filter

Array holds lists of variables of any types. Here is a few things that you should know about the array in Liquid. To have access to items in an array, you can loop through each item by inserting an interation tag featured by for, break or continue. If you want to access a specific item, you use square bracket [] notation.

The filter feature is used to offer callback function for each character in an array and build a new array that can also give the value back to confirm the true feature of that element. The callback is compatible with three arguments: the value of the element, the index of the element and the array objects being traversed.

Map in Liquid helps to create an array of values by extracting the values of a name property from another object. In the example below, supposed that the object site.page contaons all the metadata for a website. Using assign with map filter create a variable that contains only the values of the category properties of everything in the site.page objects.

How to use the map in liquid

Assumed that the object site.page contains all megadata of the website. USing assign with map filters creates creates a variable containing only the values of properties.

Input:


<!-- collection.title = "Spring", "Summer", "Fall", "Winter" -->
{% assign collection_titles = collections | map: 'title' %}
{{ collection_titles }}

Output

SpringSummerFallWinter

Conclusion

In conclusion, using map may make the shopping journey become easier. A new tag will appear in a chain on your product page. Buyers will find it more convenient when shopping around because they do not need much time to seek key tags or information.


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.

Stay in the know

Get special offers on the latest news from AVADA.