How to access metafield properties (it is a list of images)

I created a metafield for the products that has an additional a list of images that I want to display on a separate page.

I’m trying to access the first url on the metafield object. I thought it was:

{{ product.metafield.namespace.key.value.first | image_url: width: 450 }}

But this didn’t work

Hello @aabenedict,

Can you share more info about the metafield / metaobject architecture you went with, this would help a lot in helping you.

From what I see, I suppose you have:

  • A metaobject list product metafield
  • The metaobject has a file field

If this is the case, accessing the first URL would need:

{% liquid
  assign metaobject_reference_list = product.metafields.namespace.key.value
  assign first_metaobject_reference = metaobject_reference_list | first
  assign first_image_reference = first_metaobject_reference.image.value
  assign first_image_url = first_image_reference | image_url: width: 600

  # Or as a one liner
  echo product.metafields.namespace.key.value.first.image.value | image_url: width: 600

  # Or if you want to loop
  for metaobject_reference in metaobject_reference_list
    echo metaobject_reference.image.value | image_url: width: 600
  endfor
%}

Hope it helps !

Hi @aabenedict – might be a small issue: it’s product.metafields not product.metafield . Docs: Liquid objects: metafield

2 Likes

Good catch ! Might be it

Thank you! I mistyped the ‘metafield’ in the question (I meant metafields, sorry about that), but the one liner code (product.metafields.namespace.key.value.first.image.value | image_url: width: 600) helped!

Thanks again!