Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I have a metafield in my page which accepts a metaobject as its input type. In a section referencing this page metaobject I can access the fields which have a single input type no problem using this:
{% assign myMetaobject = page.metafields.custom.example.value %}
This lets me access fields with single or multi line text inputs using myMetaobject.title or myMetaobject.description. But I also have a field which accepts multiple files, specifically image and video. This is where I am struggling to access the files in a loop.
If I try this {{ myMetaobject.images }} it prints:
["gid://shopify/MediaImage/25857330184378","gid://shopify/MediaImage/25863258636474","gid://shopify/MediaImage/25863258570938"]
If I try to do a for loop on myMetaobject.images, it doesnt print anything out. Any ideas?
{% for image in myMetaobject.images %}
<div class="item-cell">
<img class="lazyload"
src=" {{ image | image_url: width: '1640x' }}"
data-widths="[475, 880, 1200, 1620]"
data-aspectratio="{{ image.aspect_ratio }}"
data-sizes="auto" />
<noscript>
<img class="grid-product__image lazyloaded"
src="{{ field | image_url: width: '1640x' }}">
</noscript>
</div>
{% endfor %}
Here is beautify code for you, kindly accept my answer.
Thanks
Hii bro do you know how we can access single image from a file list metafield using index without for loop?
{% assign myMetaobject = page.metafields.custom.example.value %}
use this for single
You can access the fields inside a metaobject in this way:
{% for metaobject in product.metafields.custom.metafield_key_name.value %}
{% if metaobject.system.type == "metaobject_identifier" %}
{{ metaobject.title }}
{{ metaobject.content | metafield_tag }}
{% endif %}
{% endfor %}
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024