Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I've been trying to figure out how to access a metafield of metaobject reference list type that has a namespace with reserved prefix in a theme app extension in Liquid. The metafield has the namespace `$app:product_options` and key `product_options` with type `list.metaobject_reference`.
This is my code in Liquid:
{% for option in product['$app:product_options'].product_options.value %}
{{ option | json }}
{% endfor %}
This does not print anything.
I've confirmed that the metafield and the referenced metaobjects are on the product I'm looking at in the local development instance of the storefront, and the code app works (e.g., I can print the ID of the product).
I've tried:
Accessing the metaobjects directly from `shop.metaobjects` works by using the fully expanded name of the namespace (i.e. using `shop.metaobjects['app--12345678912--product_option']['app--12345678912--product-option-abcde123']`), however, this does not work for metafields (i.e., `
Is there a way to access a metafield with reserved-prefixed namespace in Liquid? And if so, how and with what access control options?
Thank for your help.
Solved! Go to the solution
This is an accepted solution.
You can now use access control on Metafield definitions.
You can make the metafield's storefront access as "PUBLIC_READ". You can then access it in theme app extensions by expanding the namespace to - `app--<app_id>`
However, this is only available in the unstable version of Graphql API.
https://shopify.dev/docs/api/admin-graphql/unstable/objects/MetafieldAccess
I have been able to use app-namespaced metafields, with MERCHANT_READ access, via liquid using all of the forms:
{{ object.metafields.app--xxxxxxx--namespace.key }}
{{ object.metafields['app--xxxxxxx--namespace'].key }}
{{ object.metafields['app--xxxxxxx--namespace']['key'] }}
However, values may not be visible for 90 minutes after setting: https://community.shopify.com/c/shopify-design/outdated-server-cached-metafield-values-shown-on-orde...
Hmm, interesting... I can't make it work like this. Maybe it has sthg to do with the fact that I use metaobject reference list as the metafield type? I can't really think of anything else, since I already tried `MERCHANT_READ` and `PUBLIC_READ` on the `admin` access of the metafield and the metaobject `storefront` access is already `PUBLIC_READ`.
When I change the namespace not to include a reserved prefix, then I can access it normally. It could be cache related, but for some reason non-reserved namepsaces don't have the same problem.
This is an accepted solution.
You can now use access control on Metafield definitions.
You can make the metafield's storefront access as "PUBLIC_READ". You can then access it in theme app extensions by expanding the namespace to - `app--<app_id>`
However, this is only available in the unstable version of Graphql API.
https://shopify.dev/docs/api/admin-graphql/unstable/objects/MetafieldAccess
That API is stable now.
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024