skip to Main Content

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


  1. You should check the collection setting type:
    https://help.shopify.com/themes/development/theme-editor/settings-schema#collection:

    The output of the option the merchant selects from the drop-down is the handle of the collection.

    So, instead of:

    {{ section.settings.featured_collection.url }}

    you should use:
    {{ collections[section.settings.featured_collection].url }}

    Login or Signup to reply.
  2. I wrapped the h2 tag like this:

    {% if section.settings.title != blank %}
      <a href="/collections/{{ section.settings.home_page_featured_products }}"><h2 class="small--text-center">{{ section.settings.title | escape }}</h2></a>
    {% endif %}
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search