How to display metafields within metafields

julzevias
Tourist
6 0 1

Hello all,

We are migrating specifications for hundreds of products, and am trying to display the following metafield 

product.metafields.productDetails.brightness

  within HTML in a multitext field (I've tried single-text and rich-text too):

 

 

 

 

 

<table class="product-spec-table">
   <tbody>
      <tr>
           <td>Maximum Brightness</td>
           <td>{{product.metafields.productDetails.brightness}}</td>
      </tr>
   </tbody>
</table>

 

 

 

 

 

And in my code, I have 

 

 

 

 

 

{{ product.metafields.productDetails.specifications.value}}

 

 

 

 

 

However, I can't get the metafield to display its value; it just displays product.metafields.productDetails.brightness. Is there a way to display it within a multitext/rich text/single text metafield?

 

Thanks in advance!

Replies 2 (2)

YOD_Solutions
Shopify Partner
197 22 29

I think you might need to save "specifications" as a JSON type metafield: https://shopify.dev/docs/apps/custom-data/metafields/types

 

Then you can access it as follows:

{% assign specifications = product.metafields.productDetails.specifications %}
{% assign parsed_specifications = specifications | json_parse %}

 

And use the following to access "value" in specifications

{{ parsed_specifications.value }}

 

Please check; I haven't tested it 🙂

Founder @ JsRates: Custom Shipping Rates
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more about JsRates visit the JsRates home page or JsRates documentation
- Find JsRates on Shopify app store

tim
Shopify Expert
3274 236 1183

This depends on whether  your metafields are legacy or new ones.

Legacy metafields do not have value  property.

https://shopify.dev/docs/api/liquid/objects/metafield#metafield-deprecated-metafields 

 

You should be able to migrate legacy metafields to modern by adding metafield definitions in Settings -> Custom data

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.