Shopify themes, liquid, logos, and UX
Hi,
we have metafield for features: "first-feature,second-feature,third-feature"
It is possible to get metaobject value with something like this:
{% assign features = product.metafield.custom.features | split: ','%}
{% for feature in features %}
<span class="test123">{{ shop.metaobjects['main_features'][feature].text }}</span>
{% endfor %}
For me it returns empty...
Solved! Go to the solution
This is an accepted solution.
hello there
Unfortunately, this is not possible in Liquid as metafields and metaobjects are two separate entities. Metafields are simply key-value pairs that can be associated with various Shopify resources, while metaobjects are more complex data structures that allow you to define custom data types and store more structured data.
To retrieve the value of a metaobject, you would need to use the shop.metaobjects object followed by the handle of the metaobject, then the name of the property you want to retrieve. For example:
{% assign feature_keys = product.metafield.custom.features | split: ',' %}
{% for feature_key in feature_keys %}
{% assign feature = shop.metaobjects['main_features'][feature_key] %}
{% if feature %}
<span class="test123">{{ feature.text }}</span>
{% endif %}
{% endfor %}
This code loops over each feature key in the features
metafield, retrieves the corresponding metaobject using the shop.metaobjects
object, and then outputs the text
attribute of that metaobject if it exists.
If this fixed your issue, likes and accepting as a solution are highly appreciated
| Build an online presence with our custom-built Shopify Theme: EcomifyTheme
| Check out our reviews: Trustpilot Reviews
| We are Shopify Partners: EcomGraduates Shopify Partner
This is an accepted solution.
hello there
Unfortunately, this is not possible in Liquid as metafields and metaobjects are two separate entities. Metafields are simply key-value pairs that can be associated with various Shopify resources, while metaobjects are more complex data structures that allow you to define custom data types and store more structured data.
To retrieve the value of a metaobject, you would need to use the shop.metaobjects object followed by the handle of the metaobject, then the name of the property you want to retrieve. For example:
{% assign feature_keys = product.metafield.custom.features | split: ',' %}
{% for feature_key in feature_keys %}
{% assign feature = shop.metaobjects['main_features'][feature_key] %}
{% if feature %}
<span class="test123">{{ feature.text }}</span>
{% endif %}
{% endfor %}
This code loops over each feature key in the features
metafield, retrieves the corresponding metaobject using the shop.metaobjects
object, and then outputs the text
attribute of that metaobject if it exists.
If this fixed your issue, likes and accepting as a solution are highly appreciated
| Build an online presence with our custom-built Shopify Theme: EcomifyTheme
| Check out our reviews: Trustpilot Reviews
| We are Shopify Partners: EcomGraduates Shopify Partner
Hi guys, I'm having a similar issues and don't understand what I'm doing wrong.
I have a customer metafield containing list of metaobjects. The metafield has namespace custom and key license_new and it references a metaobject of type license which has 2 fields:
1. reference_product: reference to the product.
2. license_files: a list of generic files.
I want to display the list of metaobjects, specifically a link to the reference_product and links to download the related license_files, in the customer account page. I'm attempting to do so using
{% assign licenses = customer.metafields.custom.license_new.value %}
{% for license in licenses %}
{{ license.reference_product.value }} <br>
{% endfor %}
This doesn't seem to work and I don't understand why.
I tried a similar approach with a simpler metafiled of key licenses that only contains a list of generic files. If I try to display the files IDs by doing
{% assign licenses = customer.metafields.custom.licenses.value %}
{% for license in licenses %}
{{ license.id }} <br>
{% endfor %}
everything works as expected.
Can anyone see what I'm doing wrong? Thank you 🙂
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024