Metafields information display in Product.Liquid?

Sam_R
New Member
7 0 0

Please help.

Can'd display metafields informatino in the theme liquid pages.

What I'm doing:

  1. Using API to publish a product, that contains a "metafield" with array of object data.
  2. In my theme, product.liquid showing data with code: {{ product.metafields.global.colour }} 

Output:
blank, nothing

Expected Output:
"Black" 

Example Metafield data:

["metafield"]=>
array(14) {
[0]=>
array(4) {
["key"]=>
string(4) "colour"
["value"]=>
string(6) "Black"
["value_type"]=>
string(6) "string"
["namespace"]=>
string(6) "global"
}
[1]=>
array(4) {
["key"]=>
string(5) "model"
["value"]=>
string(11) "Summer 2016"
["value_type"]=>
string(6) "string"
["namespace"]=>
string(6) "global"
}

Any ideas?

Thanks - Chris

Thanks :-)
0 Likes
Jason
Shopify Expert
10041 119 1877

Hey Sam - I feel like we only have part of the story here. Are you saying that you have created a metafield on a product but it's blank when you try and grab it in Liquid?

  • What Liquid being used
  • What is the JSON output from that product metafields
  • Link to the product in question so we can so the output (or lack of)
★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Sam_R
New Member
7 0 0

Hey Jason,

Liquid; {{ product.global.fabric }} 

I doubt the data is publishing properly, the data may not be there. However, the resopnse received from the API is all good. I've tried around 50 variations, using key words: product / variants / global / metafields / metafield
One thing worked, but only for a few minutes. :-/
 

JSON output metafields

{{ product.metafield | json }} = null 

{{ product.metafields | json }} = {"error":"json not allowed for this object"}  

 

URL - Can't see this url helping

https://the-up-styler.myshopify.com/products/chanel-cleopatra-summer-2016

Pass: "upstyler"

 

PHP is posting data to Shopify

I was posting the "metafields" data via Product > Variant > "metafield" 
https://help.shopify.com/api/reference/product
metafield: Attaches additional information to a shop's resources.

I'm posting a few metafields, example:

["metafield"]=>
  array(14) {
    [0]=>
    array(4) {
      ["key"]=>
      string(4) "make"
      ["value"]=>
      string(6) "Chanel"
      ["value_type"]=>
      string(6) "string"
      ["namespace"]=>
      string(6) "global"
    }
    [1]=>
    array(4) {
      ["key"]=>
      string(5) "model"
      ["value"]=>
      string(11) "Summer 2016"
      ["value_type"]=>
      string(6) "string"
      ["namespace"]=>
      string(6) "global"
    }

 

Response from API is perfect. I don't know why I can't access that metafield data. So frustrating.

Thanks :-)
0 Likes
Sam_R
New Member
7 0 0

Metafields is more trouble than what it is worth.

I'm going to solve the issue another way for now.

I wish there was a way to send all data to the "description" field as JSON, and parse the JSON within the Liquid template. Some people say it's possible, however all my tests failed.

Thanks :-)
0 Likes