Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi everyone,
I'd like to use different meta object entries for several product metafields.
For instance :
Key feature 1 (metafield) = Meta object entry 1
Key feature 2 (metafield) = Meta object entry 2
...
For another product it could be for example :
Key feature 1 = meta object entry 4
Key feature 2 = meta object entry 8
I've been able to do this:
{% assign keys = shop.metaobjects.key_feature_content.values %}
{% for key in keys %}
<div>
{{ key.key_feature_title.value }}
{{ key.key_feature_description.value }}
</div>
{% endfor %}
but this content is also related to an image. The image is different for each product (so it's a metafield with file) while some key feature titles and descriptions will be the same.
From this code, I don't how I could insert the related image (img_keyfeature_1, img_keyfeature_2, img_keyfeature_3 .... and so on until 6).
Any ideas?
Thank you for your help!
Solved! Go to the solution
This is an accepted solution.
Well if anyone faces the same situation, I finally managed to do this :
{% assign keys = shop.metaobjects.key_feature_content.values %}
{% for key in keys %}
{% assign this_loop = forloop.index | modulo: 7 -%}
<div class="feature">
<div class="image_key">
{% if this_loop == 1 %}
<img src="{{ product.metafields.custom.img_keyfeature_1 | file_url }}">
{% elsif this_loop == 2 %}
<img src="{{ product.metafields.custom.img_keyfeature_2 | file_url }}">
{% elsif this_loop == 3 %}
<img src="{{ product.metafields.custom.img_keyfeature_3 | file_url }}">
{% elsif this_loop == 4 %}
<img src="{{ product.metafields.custom.img_keyfeature_4 | file_url }}">
{% elsif this_loop == 5 %}
<img src="{{ product.metafields.custom.img_keyfeature_5 | file_url }}">
{% elsif this_loop == 6 %}
<img src="{{ product.metafields.custom.img_keyfeature_6 | file_url }}">
{% endif %}
</div>
<div class="desc_key">
<h4>{{ key.key_feature_title.value }}</h4>
<p>{{ key.key_feature_description.value }}</p>
</div>
</div>
{% endfor %}
Works perfectly for me 🙂
Note: If you select the same entry for several metafields, only one of them will show. You must have 6 different entries.
This is an accepted solution.
Well if anyone faces the same situation, I finally managed to do this :
{% assign keys = shop.metaobjects.key_feature_content.values %}
{% for key in keys %}
{% assign this_loop = forloop.index | modulo: 7 -%}
<div class="feature">
<div class="image_key">
{% if this_loop == 1 %}
<img src="{{ product.metafields.custom.img_keyfeature_1 | file_url }}">
{% elsif this_loop == 2 %}
<img src="{{ product.metafields.custom.img_keyfeature_2 | file_url }}">
{% elsif this_loop == 3 %}
<img src="{{ product.metafields.custom.img_keyfeature_3 | file_url }}">
{% elsif this_loop == 4 %}
<img src="{{ product.metafields.custom.img_keyfeature_4 | file_url }}">
{% elsif this_loop == 5 %}
<img src="{{ product.metafields.custom.img_keyfeature_5 | file_url }}">
{% elsif this_loop == 6 %}
<img src="{{ product.metafields.custom.img_keyfeature_6 | file_url }}">
{% endif %}
</div>
<div class="desc_key">
<h4>{{ key.key_feature_title.value }}</h4>
<p>{{ key.key_feature_description.value }}</p>
</div>
</div>
{% endfor %}
Works perfectly for me 🙂
Note: If you select the same entry for several metafields, only one of them will show. You must have 6 different entries.
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025