Ad

How To Select Collection Using Its Name On Shopify

- 1 answer

I need to select collection using its name.

For instance, I created a menu with collection links.

I want to get collection list from the navigation menu so that I can use

{% for collection in collections-list %}

But linklists has no option to say collection or products. It just shows its link.url and link.title.

How can I do this?

I want to get collection object, not link using navigation.

Ad

Answer

It depends on the type of link you are using.

If you are using a collection type link then you can get the collection object very easily with link.object. Refer to https://help.shopify.com/themes/liquid/objects/link#link-object

If you are using a web address type than you will have to split the URL in order to get the collection handle. It will be something like this:

{% assign collection_handle = link.url | split: 'collections/' | last | split: '/' | first %}

The above code looks complex but it targets the collection URL and it take in consideration if it includes tags as well.

Pretty much these are the only two options that a link can include a collection URL.

Ad
source: stackoverflow.com
Ad