Liquid Paginate & For Loop: How does the paginate function really work, technically?

I am looking to loop through an array of items that I have. I did not realize at first that a Liquid for loop only can go up to 50.

Shopify wants us to use the Paginate function in this case. What I did was just wrap the paginate function around the for loop and set it to 55 which is what I needed.

Does this improperly use any of Shopify’s resources?

Is it okay that I am not actually creating a page while using paginate, or ajax refresh? This is for rendering small color swatches (and I simplified the meta field code in this example)

Original - This only can go through 50 times and simply stops running after 50

{%- for field in metafield.value -%}

{%- endfor -%}

Workaround: adding this pageinate tags

{%- paginate field in metafield.value  by 55-%}
    {%- for field in metafield.value -%}
        
    {%- endfor -%}
{%- endpaginate -%}

shown in the documentation but I did not need to use any filters, and I am not even sure really how the filter would work

{{ paginate | default_pagination: next: 'Older', previous: 'Newer' }}

Shopify Resource: https://shopify.github.io/liquid-code-examples/example/simple-pagination

Hi @BaileyPaserk ,

If you are trying to just loop on color swatch, I do not think you will need pagination. Use pagination if you are trying to separate the items by pages. Filters works only to products, pages, and collection. You can read more about the pagination here. In my opinion, just use the forloop for color swatch

@made4Uo Thank you, but the problem with only using the for loop was that it will not continue the loop if there are more than 50 items in the array, which there are in my case. Wrapping it in the paginate seemed to work. But I am wondering if there is anything inherently wrong doing this in my case.

Hi @BaileyPaserk ,

Please change code:

{%- paginate metafield.value by 55-%}
    {%- for field in metafield.value -%}
        
    {%- endfor -%}
{%- endpaginate -%}

Hope it helps!