Access app ID in theme block

Hi all,

I’m sorry if this is a really silly question. I’m creating my first theme app extension and app block.

I’m trying to access a metafield that our app creates on installation. At the moment I’m hardcoding the app id as follows:

{% assign modifier_list = product.metafields.app--xxxxxxxxxxx--xxxxx.assigned_modifiers_set_list.value %}

But it’s kinda annoying when switching between development apps needing to update the app id all the time.

I thought that I could possibly use the app object to do something like this:

{% assign modifier_list = product.metafields.app.assigned_modifiers_set_list.value %}

Is there an object or property available that allows app blocks to access it’s own app id for use in metafields?

Thank you so much,
Adam

Currently, there isn’t a built-in way to dynamically reference your app’s ID in Liquid.

To make life a bit easier during development, you might consider storing the app ID in a block or theme setting and then use that to build your metafield namespace dynamically:

{% assign namespace = "app--" | append: block.settings.app_id %}
{% assign modifier_list = product.metafields[namespace].assigned_modifiers_set_list.value %}

This way, you only need to update the setting in one place (or have different settings for dev/staging/production).

2 Likes

Hey Daniel,

Thank you very much for your reply and detailed solution, it’s very much appreciated :pray:t5:

I’m assuming user can overwrite this, no? Won’t this be is an issue if user overwrite it in production?