Liquid array .size suddenly not working.

MaxNodland
Tourist
10 1 2

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
820 73 140

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.

Founder of Shopify agency - Accomplishify.com
If you would like to hire us as Shopify experts, please reach out via:
  • Email michal.morek@accomplishify.com
  • WhatsApp +48 507 613 425
0 Likes
MaxNodland
Tourist
10 1 2

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
1241 162 219

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
820 73 140

Hello @MaxNodland,

You are welcome. Did it work for you?

Founder of Shopify agency - Accomplishify.com
If you would like to hire us as Shopify experts, please reach out via:
  • Email michal.morek@accomplishify.com
  • WhatsApp +48 507 613 425
0 Likes
MaxNodland
Tourist
10 1 2

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
820 73 140

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.

Founder of Shopify agency - Accomplishify.com
If you would like to hire us as Shopify experts, please reach out via:
  • Email michal.morek@accomplishify.com
  • WhatsApp +48 507 613 425
0 Likes