List-collections.liquid
From Spiffy Stores Knowledge Base
Revision as of 08:37, 17 March 2021 by Shawn (talk | contribs) (Created page with "The list-collections.liquid template is used to render a page where all of the collections in the store are listed. This template can be accessed by going to the /collecti...")
The list-collections.liquid template is used to render a page where all of the collections in the store are listed. This template can be accessed by going to the /collections URL of the store.
Re-ordering the collections
When you loop through the collections array, the collections will be output in alphabetical order by default.
{% for collection in collections %} <!-- Collection information here --> {% endfor %}
There may be instances where you want to re-order the collections listed or pick and choose which collections to display. In such cases, you can load the collections from a menu instead.
Display a product image if a collection image does not exist
If a collection does not have a collection image, it is a good practice to show a product image instead. The example below is an if statement that loads the featured image of the first product in the collection if the collection does not have its own collection image.
{% for collection in collections %} {% if collection.image %} <img src="{{ collection | img_url: '450x450' }}" alt="{{ collection.image.alt }}" /> {% else %} <img src="{{ collection.products.first | img_url: '450x450' }}" alt="{{ collection.title | escape }}" /> {% endif %} {% endfor %}