Liquid array .size suddenly not working.

MaxNodland
New Member
3 0 0

I've customized a theme for a client and it uses metafileds to show additional information on product pages.

I check for the existence of the metafields using:

{% if product.metafields.my_metafield_namespace.size > 0 %}

It's worked great for the past few months, but suddenly .size is returning null. Not even 0, just null.

The metafield object returned is not empty, it has the valid data. It's just that the .size function stopped working.

I searched the forums and found this post from 2019 that's very similar https://community.shopify.com/c/Shopify-Design/Liquid-array-length-is-not-supported-anymore/td-p/617... 

Does anyone have clues as to why this is happening? Does Shopify change these low level functions without warning, or do they fail intermittently? I'd love to have a good explanation for my client who's upset that his theme broke.

Thanks for your help!

0 Likes
Michal_Morek
Shopify Partner
487 38 77

Hello MaxNodLand,

{% if product.metafields.my_metafield_namespace and product.metafields.my_metafield_namespace.size > 0 %}

Please let me know if you have any further questions.

If you found this comment useful then please hit Like and Accept the Solution!
If you would like to hire us as Shopify experts, please reach out via email or private message.
Founder of Shopify agency - Accomplishify.com
Contact me on: community@accomplishify.com
0 Likes
MaxNodland
New Member
3 0 0

Michael, thanks for your response.

I believe metafields.invalid_namespace returns an empty array, not null. So .size should return 0.

If metafields.invalid_namespace returned null I would simply say

{% if product.metafields.my_metafield_namespace %}

 and get rid of the .size call altogether.

The real issue is that I had production code working for months and it suddenly broke without any changes to product metadata or theme code.

0 Likes
LitExtension
Shopify Partner
898 100 158

Hi @MaxNodland

You can try with this snippet:

{%- assign datas = product.metafields.accentuate.product_related_products | split: '|' | uniq -%}

{% if datas.size > 0 %}

  {% for data in datas %}

    {{ data }}

  {% endfor %}

{% endif %}

Hope this helps.

LitExtension - Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!
0 Likes
Michal_Morek
Shopify Partner
487 38 77

Hello @MaxNodland,

You are welcome. Did it work for you?

If you found this comment useful then please hit Like and Accept the Solution!
If you would like to hire us as Shopify experts, please reach out via email or private message.
Founder of Shopify agency - Accomplishify.com
Contact me on: community@accomplishify.com
0 Likes
MaxNodland
New Member
3 0 0

Not exactly - the .size function stopped working on the metafields array, even though the array was not empty.

The problem has seemed to resolved itself, in the same way the thread I linked to in the original post mentioned.

Very strange behavior.

Thanks for posting though.

0 Likes
Michal_Morek
Shopify Partner
487 38 77

Hi @MaxNodland 

Hope you're having a great day!

I could help you more I see your code. Could you share the complete code here?

If you have any further questions, please do reach out either here on the forum, or via private message/email.

If you found this comment useful then please hit Like and Accept the Solution!
If you would like to hire us as Shopify experts, please reach out via email or private message.
Founder of Shopify agency - Accomplishify.com
Contact me on: community@accomplishify.com
0 Likes