Is it possible to create a set of metafields available in all pages, collections, products...

Solved

Is it possible to create a set of metafields available in all pages, collections, products...

d4m
Tourist
5 0 1

Hi everybody,

Perhaps a silly question (new to Shopify). I wonder if there's a way to create a set of metafields available in every page (ideally also blog post, product, collection page, etc...)

So if currently when you open a page (in edit view) you can see: Title, Content, SEO fields (title, desc, url handler), and an option to select a template. 
And when you create metafields they seem to be attached to/available on THIS PAGE only. 

I would like to have metafields that are attached to a template. So if ANY page selects a template it comes with a set of ready to use metafields.
The benefit is obvious - you can use the same template for many pages while keeping content and code separately.
Also you can create sitewide content blocks that can be included on various pages.

to be clear: "pages" - any store page that a user can access in browser (regardless of a page type "product, collection, page, blog, or whatever").

Is it possible? Please clarify 🙂

Accepted Solution (1)

PaulNewton
Shopify Partner
7722 678 1628

This is an accepted solution.

@d4m , @dkarr 


@d4m wrote:

 way to create a set of metafields available in every page (ideally also blog post, product, collection page, etc...)

Yes put it on the shop object

If it needs to be some global contrivance put it on the shop {{ shop.metafields.custom.key }}, if it's a resource you can make some named /page in the admin that's no more than a glorified data holder i.e. /pages/extrastuff then reference that {{ pages.extrastuff.metafields.custom.key }} 

 

And when you create metafields they seem to be attached to/available on THIS PAGE only. 

Yes the values of the metafield are per resource

 

I would like to have metafields that are attached to a template. So if ANY page selects a template it comes with a set of ready to use metafields.

Metafields go to resources not theme assets.

If you need metafields, or other data,  consistently part of a template just put them in the template.


The benefit is obvious - you can use the same template for many pages while keeping content and code separately.

But you haven't really as you still must reference any "global" metafields in code which is little more than storing static strings indirectly. 

 

Also you can create sitewide content blocks that can be included on various pages.

You can already do this with page.content or theme snippets 

https://shopify.dev/api/liquid/objects#pages 


🙂


Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


View solution in original post

Replies 6 (6)

dkarr
Shopify Partner
5 0 2

This would be extremely helpful.

Douglas Karr
@highbridge_indy

PaulNewton
Shopify Partner
7722 678 1628

This is an accepted solution.

@d4m , @dkarr 


@d4m wrote:

 way to create a set of metafields available in every page (ideally also blog post, product, collection page, etc...)

Yes put it on the shop object

If it needs to be some global contrivance put it on the shop {{ shop.metafields.custom.key }}, if it's a resource you can make some named /page in the admin that's no more than a glorified data holder i.e. /pages/extrastuff then reference that {{ pages.extrastuff.metafields.custom.key }} 

 

And when you create metafields they seem to be attached to/available on THIS PAGE only. 

Yes the values of the metafield are per resource

 

I would like to have metafields that are attached to a template. So if ANY page selects a template it comes with a set of ready to use metafields.

Metafields go to resources not theme assets.

If you need metafields, or other data,  consistently part of a template just put them in the template.


The benefit is obvious - you can use the same template for many pages while keeping content and code separately.

But you haven't really as you still must reference any "global" metafields in code which is little more than storing static strings indirectly. 

 

Also you can create sitewide content blocks that can be included on various pages.

You can already do this with page.content or theme snippets 

https://shopify.dev/api/liquid/objects#pages 


🙂


Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


d4m
Tourist
5 0 1

Thank you, @PaulNewton . This is clear!
I have figured out myself too... this was a question of a total newbie who came from another cms world. In my favorite MODX templates are a different kind of enemy than in Shopify. But, well, you just accept it and move on 🙂  

martinpaulnorth
Shopify Partner
30 1 5

apologies for picking up an old thread, but i'm trying to create a metafield against the shop object. I can't for the life of me figure out how to do that, either through rest API or via the shopify admin console. Any advice how to create a metafield against the shop ? Many thanks!

andk
Shopify Partner
1 0 0

Same, have you figured it out?

PaulNewton
Shopify Partner
7722 678 1628

Start here https://shopify.dev/docs/apps/custom-data/metafields 

Direct example of creating a shop metafield:

https://shopify.dev/docs/api/admin-rest/2023-01/resources/metafield#:~:text=Create%20a%20metafield%2... 

Otherwise use a metafields app.

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org