I have a metafield that exists across a number of page types that I use in the theme.liquid file. Instead having to write a condition for: page.metafields.namespace.key, collection.metafields.namespace.key, blog.metafields.namespace.key, etc. I want to just use a generic metafields.namespace.key.
I can get the resource with request.page_type, but I can’t find any way to connect it as a variable. I tried a number of things:
So you can just get it in the correct structure: page.metafields.namespace.key, collection.metafields.namespace.key, blog.metafields.namespace.key, etc
The thing is that metafields are stored in specific instance of an object (in each specific blog, collection, page etc). In order to access metafields, one must use a proper Liquid code of the given structure:
{{ resource.metafields.namespace.key.value }}
If the “request” variable doesn’t represent nor contain the actual instance of an object, you won’t be able to access the metafields that belong to it.