Trying to limit number of products shown in collection with separate template

Lani_S
Tourist
12 0 0

I created a template named collection-new-arrivals.liquid calling a section named collection-new-template.liquid

I used the code

{% for product in collection.products limit=92 %}

Nothing is happening. I think I am missing something. Help please. Thanks!

0 Likes
Lani_S
Tourist
12 0 0

Is there other information I need to include to get help with my question?

0 Likes
Jason
Shopify Expert
10037 119 1873

When using the limit property in a for loop it needs to be referenced like so:

{% for item in numbers limit:2 %}

Note the use of :, not =.

Depending on how you're using that code it might also not return 92 products. I'll assume it will return 50 with what I've seen so far.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
Lani_S
Tourist
12 0 0

Thanks, Jason. I changed = to :, but it is still not working. I have included the full page code below. 

<div data-section-id="{{ section.id }}" id="collection-new-template">
{% assign number = section.settings.products_per_page %}
{% paginate collection.products by number %}
  
  <div id="collection-description" class="desktop-12 mobile-3">
    <h1>{{ collection.title }}</h1>
  </div>

  <div class="clear"></div>
  
  {% unless section.settings.sidebar %}
  <div id="full-width-filter" class="desktop-12 tablet-6 mobile-3">
      {% for block in section.blocks %}
      {% include 'filters' %}
      {% endfor %}
  </div>
  {% endunless %}
  
{% if section.settings.sidebar %}
{% include 'collection-sidebar' %}
{% endif %}
<div class="{% if section.settings.sidebar %}desktop-9 tablet-6{% else %}desktop-12 tablet-6{% endif %} mobile-3">
  <div id="product-loop">
    {% for product in collection.products limit:92 %}
    <div class="product-index {% if section.settings.products_per_row  == 2 %}desktop-6 tablet-half {% cycle ' first', ' last' %}{% elsif section.settings.products_per_row  == 3 %}desktop-4 tablet-2 {% cycle ' first', '', ' last' %}{% elsif section.settings.products_per_row == 4 %}desktop-3 tablet-half {% cycle ' first', '', '', ' last' %}{% endif %} mobile-half" data-alpha="{{ product.title }}" data-price="{{ product.price }}">   
      {% include 'product-listing' %}
    </div>
    {% endfor %} 
  </div>
</div>

{% include 'pagination' %}

{% endpaginate %}
</div>


{% schema %}
{
    "name": "Collection Page",
	"max_blocks" : 6,
    "settings": [
      {
        "type":      "range",
        "id":        "products_per_row",
        "min":       2,
        "max":        4,
        "step":       1,
        "label":     "Products per row",
        "default":   3
      },
      {
        "type":      "range",
        "id":        "products_per_page",
        "min":       2,
        "max":        50,
        "step":       1,
        "label":     "Products per page",
        "default":   46
      },
      {
        "type": "checkbox",
        "id": "sidebar",
        "label": "Show sidebar"
      }   
    ],
   "blocks":[  
      {  
         "type":"menu",
         "name":"Menu",
         "settings":[  
            {
               "type": "link_list",
               "id": "side_nav",
               "label": "Sidebar menu"
            },
           {
            "type": "text",
            "id": "title",
            "label": "Menu title",
            "default": "Explore"
           }
         ]
      },
      {  
         "type":"vendor_list",
         "name":"Vendor list",
		 "limit": 1,
         "settings":[  
          {
          "type": "text",
          "id": "shop_by_designer_title",
          "label": "Vendor list title",
          "default": "Shop by Designer"
          }
         ]
      },
      {  
         "type":"sort_by",
         "name":"Sort by",
		 "limit": 1,
         "settings":[  
          {
          "type": "text",
          "id": "sort_by_title",
          "label": "Sort by title",
          "default": "Sort"
          }
         ]
      },
      {  
         "type":"filter",
         "name":"Filter",
		 "limit": 3,
         "settings":[  
          {
          "type": "text",
          "id": "filter_by_title",
          "label": "Filter by title",
          "default": "Filter by"
          },
          {
          "type": "textarea",
          "id": "filter_by",
          "label": "Tag filter"
          }
         ]
      }
   ]
  }
{% endschema %}

 

0 Likes
Sasan_Baho
New Member
1 0 0

It works for me! Thanks!

0 Likes