Paginate displays all products in all pages

Paginate displays all products in all pages

xyzbarna
Shopify Partner
3 0 1

Hello there,

I've something like that in a section:

 

{% paginate section.settings.selected_collection.products by 1 %} 
  {%- for product in section.settings.selected_collection.products -%} 
    {% render 'product-card-A', product: product %} 
  {%- endfor -%} {

  % render 'pagination-A', pagination: paginate %} 
{% endpaginate %}

 

I'm working with a 4 different products as dummy content and this code results in 4 pages (which is fine, 1x4), but displays all the 4 products in each page. The pagination nav works fine.

 

I'm missing something?

Reply 1 (1)

xyzbarna
Shopify Partner
3 0 1

Ok, I'm not 100% sure, but it seems that doesn't work because collection is not a global object. I solved it this way: Instead of iterating the products directly from this array:

section.settings.selected_collection.products

 I used the global object collections:

{%- assign current_products = collections[section.settings.selected_collection] -%}

{% paginate current_products.products by 1 %}
  {%- for product in current_products.products -%}
    {% render 'st-product-card-A1', product: product %}
  {%- endfor -%}

  {% render 'st-pagination-A', pagination: paginate %}
{% endpaginate %}

(section.settings.selected_collection is a setting type collection, and it returns the collection's handle)