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...") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
When you loop through the collections array, the collections will be output in alphabetical order by default. | When you loop through the collections array, the collections will be output in alphabetical order by default. | ||
<pre> | <pre> | ||
− | {% for collection in collections %} | + | {% for collection in shop.collections %} |
− | + | <!-- Collection information here --> | |
{% 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. |
+ | |||
+ | # Create a menu called "Collections" | ||
+ | # Add the collections you would like to feature to the menu, 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== | ||
Line 14: | Line 17: | ||
<pre> | <pre> | ||
− | {% for collection in collections %} | + | {% for collection in shop.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 %} | {% endfor %} | ||
</pre> | </pre> |
Latest revision as of 08:42, 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 shop.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.
- Create a menu called "Collections"
- Add the collections you would like to feature to the menu, 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 shop.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 %}