Difference between revisions of "List-collections.liquid"

From Spiffy Stores Knowledge Base

(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...")
 
Line 8: Line 8:
 
{% endfor %}
 
{% endfor %}
 
</pre>
 
</pre>
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.
+
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. This is a theme dependent tweak, so may not be supported by all themes. 
 +
 
 +
1. Create a menu called "Collections"
 +
2. Add the collections you would like to feature and re-order your menu as needed
  
 
==Display a product image if a collection image does not exist==
 
==Display a product image if a collection image does not exist==

Revision as of 08:39, 17 March 2021

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. This is a theme dependent tweak, so may not be supported by all themes.

1. Create a menu called "Collections" 2. Add the collections you would like to feature and re-order your menu as needed

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 %}