Accessing App-owned metafields from theme extension block liquid

Hi,

On https://shopify.dev/apps/metafields/app-owned it says that:

Unlike private metafields, app-owned metafields can be accessed using Liquid.

I have created a sample theme extension for my app and on a sample liquid block file I am trying to display the app owned metafield which was created earlier using the steps on https://shopify.dev/apps/metafields/app-owned#create-an-app-owned-metafield

Contents of blocks/sample-block.liquid

Value: {{ app.metafields.settings.test }}

{% schema %}
...
{% endschema %}

App metafield create result with type single_line_text_field and value test-value:

Array
(
    [metafieldsSet] => Array
        (
            [metafields] => Array
                (
                    [0] => Array
                        (
                            [id] => gid://shopify/Metafield/212....
                            [namespace] => settings
                            [key] => test
                        )
                )
            [userErrors] => Array
                (
                )
        )
)

I’m expecting to see “Value: test-value” on the shop after adding the block in my theme, however I see "Value: ".

Are app-owned metafields specifically designed to be used only inside schema available_if described on https://shopify.dev/apps/online-store/theme-app-extensions/extensions-framework#conditional-app-blocks or they can be also used like I do?

Thanks!

This also suggests that it should work: https://shopify.dev/changelog/new-app-liquid-object

A new Liquid app object is available for use within the context of theme app extensions and app proxies. The app object can be used to access an app’s metafields.

I see a similar topic here: https://community.shopify.com/topic/1311365

I am sure I have created the metafield with the correct AppInstallation ID, since I get a result to this GraphQL query:

{
    currentAppInstallation {
        metafield(namespace: "settings", key: "test") {
            value
        }
    }
}

Response:
Array
(
    [currentAppInstallation] => Array
        (
            [metafield] => Array
                (
                    [value] => test value
                )

        )

)

I’m also sure that I’m using the theme app extension liquid file and not a regular theme liquid file to access the variable value with {{ app.metafields.settings.test }}

I’m using 2022-10 API version on a development store and my app extension has DEVELOPMENT STORE PREVIEW option enabled.

Do I need to do something special to enable app-owned metafields access?

@edo888 code looks fine

  • have you activated the theme app block on the publish theme?

  • check you are in public theme preview mode?

  • are you creating meta filed passing the appid Correct?

Yes to all 3 questions, but still I’m getting blank output for {{ app.metafields.settings.test }}

Does it work for your development shop or it is a public shop?

Is your app published on Shopify app store?

Thanks!

Did it from scratch, made sure just one app is installed and all works fine.

Turned out I was using another installed app token to set the app-owned metafields, however I was publishing the app theme extension on another app.

So it works as expected.

Thanks!

I know you have already found the answer. I got the same issue and I want to know where can you see the value

Value: {{ app.metafields.settings.test }}