Use metafields on homepage?

New Member
19 0 0

Hi,

I'm attempting to find a way to use metafields on the homepage. The only way I know of to add metafields is to go to admin > pages > (specific page) and add them via the shopifyFD plugin. And because the homepage is not listed under the admin > pages section, I can't see how to do that. Is there some way to directly access and display a metafield if I add it to a different page? For example, if I were to use something like: 

{{ page.handle.metafieldName }}

to access a metafield after adding it to a page, and just display it on the homepage through this method?

Or, is there some other way to use metafields on the homepage? 

Thanks ahead of time for your help.

0 Likes
Shopify Expert
9807 92 1560

What sort of info are you needing to store in a metafield? Some context and further info would help determine if you should even be using a metafield at all.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
New Member
19 0 0

For the sake of the argument, we'll just assume that the content used should be stored in a metafield. I'm mainly looking for the answer to whether we can call a metafield on the homepage. Thanks for any help you can provide.

0 Likes
Shopify Expert
9807 92 1560

can call a metafield on the homepage

You'd need to store the metafield on something since the homepage isn't an object.

That something could be a the shop, product, page, etc. You'd then reference that object specificially and pull out the metafield resources you need. For example to pull from the shop object:

{{ shop.metafields.foo.bar }}

or product:

{{ all_products['some-handle'].metafields.foo.bar }}

etc.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like
New Member
19 0 0

Thanks, Jason. To clarify, in order to grab a metafield from a page and display it on the homepage, I would follow the format:

{{ page['handle-name'].metafields.namespace.key }}

? I want to make sure I'm following correctly, as I tried this and it hasn't worked. 

Edit: I've also tried

{{ page['handle-name'].metafields["namespace"]["key"] }}

 

0 Likes
New Member
19 0 0

Weird, I guess Jason removed his replies here.

Anybody else have any idea how to use metafields on the homepage? Or in any other files that aren't defined in the pages admin area? Still trying to get this to work.

0 Likes
New Member
19 0 0

Ahh, I finally solved it.

If anybody wants to know how to use metafields on the homepage, or any other type of file/page that isn't in the page admin area, here it is. Obviously, first you have to create the metafield in a page in the page admin area. Then, you access that metafield with this format:

{{ pages.myPageHandle.metafields.myNamespace.myKey }}

 

0 Likes
Shopify Expert
17 0 3

You showed us the general answer, but what is the handle for the homepage?   

0 Likes
Shopify Partner
8 0 0
{{pages.{{page.handle}}.metafields.global.logo}}

 is not working , can you elaborate?

0 Likes
Shopify Partner
1 0 1

You can't use those "{{" curly brace delimiters inside another set of curly brace delimiters. Try assigning it as a variable first. Something like this (not tested, but should work):

{% assign the_handle = page.handle %}
{{ pages.the_handle.metafields.global.logo }}
1 Like