Can't add collection to user created page template

Shopify Partner
1 0 0

Hi,

I'm new to shopify and I ran into an issue when editing the code of the 'Streamline' theme.  I added a sneakers page that I want to show a list of sneaker collections such as, adidas, nike, and so on.  I decided to create a new page template called 'page.list-sneakers.liquid' and also a new section called 'list-sneakers.liquid' because if I put the 'list-collections-template' in my page template then that section changes on all pages.  My new section is an exact duplicate of the 'list-collections-template'  because I want it to do the exact same thing except make changes to that template wherever it is in my website.

 

My issue is that when I go to my 'Sneakers' page and select the radio button to select the collections I want, it doesn't do anything.  I inspected it in chrome and noticed it was throwing the error: 'Uncaught TypeError: cannot read property 'collection' of undefined'.

 

Here is what my section code looks like:

<div class="page-width page-content" data-aos>

  {% if section.settings.title_enable %}
    <header class="section-header appear-delay">
      <h1 class="section-header__title">
        {{ 'collections.general.catalog_title' | t }}
      </h1>
    </header>
  {% endif %}

  {%- assign blocks = section.blocks | sort: 'collection.all_products_count' -%}

  <div class="skrim-grid appear-delay-1">
    {% if section.settings.display_type == 'all' %}
      {% case section.settings.sort %}
        {% when 'products_high' or 'products_low' %}
          {%- assign collections = collections | sort: 'all_products_count' -%}
        {% when 'date' or 'date_reversed' %}
          {%- assign collections = collections | sort: 'published_at' -%}
      {% endcase %}
      {% if section.settings.sort == 'products_low' or section.settings.sort == 'date' or section.settings.sort == 'alphabetical' %}
        {% for collection in collections %}
          {% include 'collection-grid-item' %}
        {% endfor %}
      {% else %}
        {% for collection in collections reversed %}
          {% include 'collection-grid-item' %}
        {% endfor %}
      {% endif %}
    {% else %}
      {% for block in section.blocks %}
        {%- assign collection = collections[block.settings.collection] -%}
        {% include 'collection-grid-item' %}
      {% endfor %}
    {% endif %}
  </div>
</div>

{% schema %}
  {
    "name": "Collections list page",
    "settings": [
      {
        "type": "checkbox",
        "id": "title_enable",
        "label": "Show title",
        "default": true
      },
      {
        "type": "paragraph",
        "content": "All of your collections are listed by default. To customize your list, choose 'Selected' and add collections."
      },
      {
        "type": "radio",
        "id": "display_type",
        "label": "Select collections to show",
        "default": "all",
        "options": [
          {
            "value": "all",
            "label": "All"
          },
          {
            "value": "selected",
            "label": "Selected"
          }
        ]
      },
      {
        "type": "select",
        "id": "sort",
        "label": "Sort collections by:",
        "info": "Sorting only applies when 'All' is selected",
        "default": "alphabetical",
        "options": [
          {
            "value": "products_high",
            "label": "Product count, high to low"
          },
          {
            "value": "products_low",
            "label": "Product count, low to high"
          },
          {
            "value": "alphabetical",
            "label": "Alphabetically, A-Z"
          },
          {
            "value": "alphabetical_reversed",
            "label": "Alphabetically, Z-A"
          },
          {
            "value": "date",
            "label": "Date, old to new"
          },
          {
            "value": "date_reversed",
            "label": "Date, new to old"
          }
        ]
      }
    ],
    "blocks": [
      {
        "type": "collection",
        "name": "Collection",
        "settings": [
          {
            "label": "Collection",
            "id": "collection",
            "type": "collection"
          }
        ]
      }
    ]
  }
{% endschema %}

If anyone can help me figure out why this isn't working, I would much appreciate it!  Thanks.

0 Likes