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:
Setting the storefront access of the metaobjects to PUBLIC_READ and the metafields’ admin access to PUBLIC_READ as well.
Using just the key without the namespace on the product.metafields object.
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., `
product.metafields[‘app–12345678912–product_options’][‘product_options’] does not print anything).
Is there a way to access a metafield with reserved-prefixed namespace in Liquid? And if so, how and with what access control options?
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.
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.