Metafields not displaying in product.liquid

ShopifyKI
Visitor
3 0 0

We had a third party import values as metafields into shopify. I'm trying to use the metafields on our product.liquid page but they're not displaying. Here's an example of the code:

        {% if product.metafields.global.attribute.material-color %}  
        <div class="description rte" itemprop="description">  
         <b>Material Color:</b> {{ product.metafields.global.attribute.material-color }}
        </div>
        {% endif %}

 

The name space is: global
Key is: attribute.material-color

Is it because of the period in the key? All the values that were transfered used that format; attribute.NAME.

Replies 3 (3)

mffowler
Shopify Partner
31 0 5

Reference: https://help.shopify.com/themes/liquid/objects/metafield

I use a simple call which just uses the namespace:

{% for field in product.metafields.mColour %}<b>Colour:</b> {{ field | last }}<br />{% endfor %}

- Mike

Jason
Shopify Expert
11190 225 2282

If you need to grab a specific metafield with a period in the name you can do so like this:

{{ product.metafields.global['attribute.material-color'] }}

 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

ShopifyKI
Visitor
3 0 0

That worked. Thank you so much! I was having a lot of trouble with this.