Ad

How To Get Collection Object In Shopify When Selected From Customize Window

- 1 answer

I have created a section where I have written in schema to select a collection. I can view this option in customize window of shopify. Now on code part of this section I want the whole collection object so I can get image, title, description etc. from that collection.

{% schema %}
{
  "name": "Featured Collection",
  "settings": [
    {
      "type": "collection",
      "id": "featured_collection",
      "label": "Collection"
    }
}
{% endschema %}

How I am trying to get the collection object

{% assign collection = section.settings.featured_collection %}

But this returns only the collection handle. Please tell me how could I get collection title, image & description

Ad

Answer

You have the collection handle. collections is a global Liquid object. Therefore you can reference any specific collection using the handle. Why can you not just do this?

{% assign x = collections['my-handle'] %}

And then use the title, image and description assigned to x?

Ad
source: stackoverflow.com
Ad