Visible_if should work with app metafields

Hi,

App blocks support the convenient available_if at the block level to hide/show certain blocks based on an app metafield.

It would be great to be able, inside a block, to hide/show some settings depending on on an app metafield as well (for instance, to gate some specific features to certain customers). Unfortunately, if we try to use “visible_if”: “{{ app.metafields.foo.bar }}” Shopify CLI will complain that it is not a valid expression.

Thanks.

1 Like

Hi Michael! :smiling_face_with_sunglasses: @bakura10

Not sure if it’s related to app-owned metafields, but they mentioned that it can’t read runtime context. And disclaimer for the rest of this post - I have not tested anything with app-owned metafields.. :melting_face:

Another possible related post: Visible_if doesn't seem exactly compatible with dynamic data sources - #2 by misha

Not sure if the following will even work. But having value_from_metafield visible and then assigning that field a dynamic source linked to your metafield, should at least. But I see that wouldnt work from a theme developer perspective…

    {
      "type": "text",
      "id": "value_from_metafield",
      "label": "Value from app.metafields.foo.bar"
      "visible_if": "{{ false }}",
      "default": "{{ app.metafields.foo.bar }}"
    },
    {
      "type": "header",
      "content": "app.metafields.foo.bar has a value!",
      "info": "some text...",
      "visible_if": "{{ section.settings.value_from_metafield == blank }}"
    }