Im looking to implement a custom html code to my product page that is dynamic to the product on the page, that will display text and icons of the coffee flavor and roast profiles. I have meta objects set up for unique flavor profiles and coffee roast profile. I would love some help in getting these set up properly in the code. Ive currently got the section hard coded but when I try to make it dynamic with a for loop and add the key values of the meta object nothing happens for me. Ive attached an example of what im looking to achieve. and also included the current hard code that im working with. any insights would be extremely appreciated.
I also referenced your shared link and updated my code, but its not working for me. I just updated the flavor profiles first, thinking ill tackle the roast profile next so I left the hardcode in place for medium roast. I tried with {{ preference.label }} and {{ preference[“label”] }}, nothing worked.
Sure, {{ Roast_Profile.Roast Indicator | img_url: ‘32x’ }} will give you an error as you’ve missed the underscore – Roast_Indicator.
Also – to reference metafield you need to use namespace and key, like so: product.metafields.namespace.key. And then you may append .value to get the MF value (if it’s complex MF).
So using product.metafields.shopify.custom.flavor_profile is not right.
So, I’d do this:
{% if product.metafields.custom.flavor_profile %}
{% for profile in product.metafields.custom.flavor_profile.value %}
### {{ profile.label }}
{% endfor %}
{% endif %}
Note that .label can be used without .value (it’s a single line text, simple field), but .icon needs it to convert it to image object in order to use img_url filter