I’m theming the basic stuff for a webshop and trying to add a ‘view collection’-button to the featured collection on the home page. In the documentation it states that normally I just need to do collection.url and get the url. But it doesn’t seem to work. Can someone say what I do wrong?
(https://help.shopify.com/themes/liquid/objects/collection#collection-url)
{% if section.settings.show_view_all %}
<hr class="hr--clear">
<div class="text-center">
<a href="{{ section.settings.featured_collection.url }}" class="btn">
{{ 'collections.general.view_all' | t }}
</a>
</div>
{% endif %}
</div>
{% schema %}
{
"name": "Featured collection",
"class": "index-section",
"settings": [
{
"type": "text",
"id": "title",
"label": "Heading",
"default": "Featured collection"
},
{
"type": "collection",
"id": "featured_collection",
"label": "Collection"
},
2
Answers
You should check the collection setting type:
https://help.shopify.com/themes/development/theme-editor/settings-schema#collection:
So, instead of:
{{ section.settings.featured_collection.url }}
you should use:
{{ collections[section.settings.featured_collection].url }}
I wrapped the h2 tag like this:
As I do not ever plan to make the collection slug different, this works for me. Your mileage may vary. This is using the ‘Simple’ theme.