Metafield key with special character: how to access via liquid?

Metafield key with special character: how to access via liquid?

ios14
Visitor
1 0 0

Hello,

 

I have a metafield with a "/" character in key name. Everything is ok accessing it via REST but how to access it via liquid? 

 
{"key":"A/C","value": "A/C", "type":"string","namespace":"global"}
 
Tried:
product.metafields.global."A/C"
product.metafields.global.A\/C
product.metafields.global.A%2FC
 
nothing works
Reply 1 (1)

Liam
Community Manager
3108 340 873

Hi Ios14,

 

It's not possible to access a metafield via liquid if it contains a "/" character in the key name. This is due to the fact that the "/" character is treated as a path separator in Liquid and is not valid in variable names. It's recommended to avoid using special characters like "/" in metafield keys to ensure compatibility with all parts of Shopify's system, including Liquid.

 

You may need to rename your metafield key to something without the "/" character to be able to access it via Liquid. For example, you might change "A/C" to "AC" or "A_C". Then you would access it via Liquid, eg:

product.metafields.global.AC
product.metafields.global.A_C

Please note that renaming the metafield key will require updating any existing data or code that references the old key name.

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog