ajaxshopifyliquidliquid-layout

Shopify site liquid does not support pagination on array variables


Here is the scenario i am trying to achieve but unable to:

At the top of my collection.liquid page i do this:

{% assign sorted_products = collection.products| sort: 'tags'%}
{% paginate sorted_products by 15%}

however, this will end up with the following error:

Liquid error: Array 'sorted_products' is not paginateable.

I know that I can paginate through collection.products but I will lose the sort by tag that way.

This is necessary to lay out the site as expected - Anyone knows how I can get around this issue in Shopify?

EDIT

After asking this question on a different site I got the following response?

But what happens when a product has multiple tags? Regardless, tags aren't a string but rather an array - sorting it won't get you the expected results.

This idea still won't work with pagination since you will only ever sort the paginated set and not the entire collection.

If you need to sort the entire collection you will need to pull in all products with JavaScript (with ajax), sort those using whatever method you need with JavaScript, then insert the products into the DOM.


Now I have created the JS file but I can't seem to call that from the liquid file

Any Ideas?


Solution

  • I managed to do this by paging but with a much higher limit; I could then sort and get what i need.