Liquid array .length is not supported anymore?

Solved
Tourist
11 1 5

We have some stores with themes that uses array.length in their code.

Lately these themes stopped working correctly.

After changing to array.size everything comes back to normal.

For example, the following condition will resolve as false, even though products is not empty:

    {% if products.length > 0 %}

This on the other hand, works correctly:

    {% if products.size > 0 %}

Did Shopify deprecated the use of .length for arrays lately?

0 Likes
Astronaut
1082 147 272

Not sure, since I've been working in Shopify -- About a year and a half, it's always been .size -- The only thing I know that uses .length is 

 

{% if forloop.length > 10 %}

 

Seems Shopify will just change stuff without anyone knowing though. We had an extreme crisis this morning where for some reason, our product carousels seemed to be getting spit out on an infinite loop. We could not figure out what the problem was, because even if we deleted the loop completely from the snippet, it was still outputting many many many carousels. After about 3 hours of troubleshooting and no help from Shopify support, we figured out that the problem was for some reason, we can no longer pass an object to a snippet. For instance we had

 

{% assign collection = collections.t-shirts.products %}
{% include 'product-slider' with collection, collection_handle: "t-shirts" %}

We have had this set up since the store launched and have had no issues with it to today. Instead we had to not pass the "collection" variable, and instead reassign it based on the value of collection_handle in the product-slider snippet itself. Also I just read that "include" has been depreciated and now it's "render", which render doesnt work for us at all... Not sure what's going on over there.

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes

Success.

Astronaut
1082 147 272

Update on my previous post, it now appears that BOTH ways of doing this are working again as expected. Include with passing variables as well as render. Again, no idea what's going on over at Shopify, but everything appears to be functioning as it should again.

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
1 Like