Reputation: 1
I'm trying to fetch metafields in main-product.liquid file of dawn theme to display some custom fields. This metafield is applied on variants
{% assign metafield = product.metafields namespace.key| json %}
Value: {{ metafield.value }}
This code is not fetching metafields. Is there anything wrong with the liquid code
Upvotes: 0
Views: 446
Reputation: 11427
Assuming your product has metafields, then you could use the code:
{% assign metafield = product.metafields.namespace.key | json %}
Value: {{ metafield }}
Note here that a key has a value. So in your experiments you may also try something like this:
{% assign metafield = product.metafields.namespace.key %}
Value: {{ metafield.value | json }}
But you should note that since your value may have been originally stored as JSON, there is no point in running it through the json filter. You can just see that the value you got was json and therefore your JS code will consume it fine. Example?
{% assign metafield = product.metafields.namespace.key %}
Value: {{ metafield }}
There are some, shall we say, inconsistencies when using Metafields that you can expose to yourself in 2 minutes of testing!
Upvotes: 0