Ad

Shopify Liquid Object Rules

- 1 answer

From Shopify's demo https://help.shopify.com/en/themes/liquid/objects

{% for product in collections.frontpage.products %}
  {{ product.title }}
{% endfor %} 

This piece of code shows the object collection outputing title {{ product.title }}

Where does the loop collections.frontpage.products come from?
I dont see frontpage in the list of objects, is this a reserved special object? If so are there others?
What are the rules concatenating objects together like this?

Shopify's documentation is not clear where and how I can join objects together.

Ad

Answer

You will need to read more about collections and how for loop work.

The following line collections.frontpage.products means -> Get me all Products inside the collection that have a handle called frontpage.

So you call a specific collection when you target it's handle this way collections.COLLECTION_HANDLE or this way collections[COLLECTION_HANDLE].

The frontpage collection is the default collection that comes with Shopify. Another default collections is the all collection, that doesn't need to have a collection page.

So if you go to your Shopify admin and look into Products -> Collections you should see a collection called Homepage that has a handle of frontpage. You are targeting that collection.


So to answer your question - No frontpage is not a special object, it's just a handle of a collection.

You can call a different collection this way as well collections.all.products where it will return all products no matter in which collection they are attached to, where all is the exception and you can call it like a special handle, since it doesn't require a collection to be created in order to exist. ( but at the same time you can overwrite it if you create an all collection )

Ad
source: stackoverflow.com
Ad