Is it possible to specify metafields in theme? I’m thinking either in a header part of the liquid template file or in the settings_data.json file or somewhere?
That would enable us to have different meta fields for different page tempaltes and to specify that information in code where it is under source control.
To be clear, I’m not asking how to access the metafield data once it’s set. Thats well documented and straight forward. I’m asking how to define in the theme what metafield keys should have form fields in the corresponding edit screens in /admin.
So, if for example I have a template /page.coffee.liquid there might be a header section:
““
/page.coffee.liquid
----------------------------------
Fields:
extras
Origin: String
Strength: integer
Options: radio
Milk
Sugar
----------------------------------
<h1>Hi, checkout your coffee</h1>
<ul>
<li>Origin: {{ extras.Origin }}</li>
<li>Strength: {{ extras.Strength }}</li>
<li>Milk n Sugar: {{ extras.Options }}</li>
</ul>
““
Shpify would then now that if a product uses this template (selected in the admin interface) then these metafield options would show in the edit screen in admin.
This is an example of how it could work to enable me to do what i want, which is:
Define metafield controls displayed in the admin area per template within a config or template file.
2
Answers
Biggest and most incredible thing I have found to help with metafields is this Chrome Extension by FreakDesign called ShopifyFD.
It’s a Chrome extension that — once clicked and activated — extends your Shopify admin pages to give you complete access to current metafields as well as any new ones that you want to add.
I just found it the other day and I got so giddy with the new doors that opened up.
This will allow you to control your metafields per page and then handle your logic elsewhere.
Source: https://freakdesign.com.au/pages/shopifyfd
Shopify doesn’t work that way. You’d do this with an app where you would link the template and sets of metafields.
The app would use the embedded app sdk so that it can be embedded in the Shopify admin
The app would provide an admin link on the product page. Your app would check the product template and look up the metafields needed and then present those with appropriate drop-downs/validation etc.