A space to discuss online store customization, theme development, and Liquid templating.
How does one loop through metaobject metafields? If I know the specific key for a given field, I can access it directly, but it seems like it shouldn't be difficult to loop through them all with a simple for iteration.
Example, this works as it should (metaobject is being accessed through a product metafield):
{% assign my_metaobject = product.metafields.custom.my_metaobject.value %} {{ my_metaobject.a_known_key.value }}
I feel like something like the following should easily be possible, but I can't figure it out:
{% assign my_metaobject = product.metafields.custom.my_metaobject.value %} {% for unknown_field in my_metaobject.metafields %} //Loop over every metafield in the metaobject {{ unknown_field.value }} {% endfor %}
Any help would be great! Hard coding each metafield seems needlessly un-dynamic 😕
That was exactly what I was looking for. Many many thanks 🙂
Hey! Could you share the solution? I'm trying to do the same with no luck and it seems like @peter_pro3's answer was deleted.
Hey! This worked out for me.
{% assign metafield = product.metafields.custom.characteristics.value %}
{% for metaobject in metafield %}
{{ metaobject.title }}
...
...
{% endfor %}