Shopify: How to show specific collection on the collection template

10,362

To access specific collection attributes, you must know collection handle and use this kind of code :

{{ collections['the-handle'].url }}

So to achieve what you want to do, here is what you could do:

{% assign collection_handle = 'the-handle-of-collection-you-want' %}
{% for product in collections[collection_handle].products %}
    Do your stuff
{% endfor %}

Note that you cannot access a collection through its title. Only handle.

Learning more about what's handle: https://help.shopify.com/themes/liquid/basics/handle

HTH

Share:
10,362
jhawes
Author by

jhawes

I'm a project manager and front-end developer in Lebanon, MO. I have a passion for organization, process improvement, administration and have a lot of experience in web development and front-end development as well. Currently I develop primarily in WordPress, RapidWeaver, and Shopify. I also focus heavily on WCAG compliance and SEO. Outside of work you'll find me almost doing nothing but kid stuff. I have 5 boys and a girl (oldest is 8), so we are always getting out. We love parks, camping, water, and plain 'ol exploring.

Updated on June 08, 2022

Comments

  • jhawes
    jhawes about 2 years

    I'm editing the Section/collection-template.liquid file (this file is referenced to by the Template file "collection.liquid").

    My goal is to show a specific collection by it's Title.

    I've tried a few different things I've found online, but they're a bit outdated, so my guess is they've changed, though maybe I'm just making the change incorrectly.

    I've tried changing their existing For loop from:

    {% for product in collection.products %}
    

    To:

    {% for product in collection['Collection Title'].products %}
    

    But that method doesn't appear to work anymore, though past forum posts referenced it.

    I then tried leaving the For loop as it was and then immediately placing an If statement around the calls to grab the product's details... it does seem editing the For loop would be the better of two approaches though.

    {% if collection.title == 'Collection Title' %} ... {% endif %}
    {% if collection.title contains 'Collection Title' %} ... {% endif %}
    

    In none of these attempts has anything showed up.