Issue with Dynamic APP_ID in Theme App Block Schema Settings

Hi, I need some help with the Theme App Block extension liquid schema. Is there any way to dynamically reference the APP_ID in the schema settings depending on the app? I couldn’t find a similar topic, so if this has already been asked, please send me the link.

Our company is developing an app, and we are using the Theme App Block. We have different development environments: local, development, staging, and production. We store information in a metaobject and want the user to be able to choose the correct metaobject for an app block from a set of available metaobjects. To achieve this, we use the metaobject block type, and it has a required property called metaobject_type, where the value is something like app--<appid>-basic-content. The issue I have is that the is not dynamic, and this becomes a problem because each environment uses its own app with a unique ID. However, the value needs to be hardcoded in the schema, which causes complications.

Is there a solution to make this value dynamic, depending on the app, so it can work like a variable tied to the specific app, as this block works in the context of the app? Would it be possible to use something like the Admin API $app: prefix? Perhaps I missed something in the documentation…

Creating a metaobject with a general type does not work because I need the metaobject and its definition to be deleted when the app is deleted. This is impossible if the user deletes the app because we lose API access and cannot remove it.

I would greatly appreciate any help or advice!

1 Like

Hi @Liam-Shopify! Sorry for bothering you, but could you please check out my request/question? I’d really appreciate your feedback!

Hi there! So, can someone help me with my request? Huge thanks in advance!

cc @Liam-Shopify

This same type of DX problem is across all types of extensions- checkout, customer accounts, Flow actions, etc.

I wrote a CLI tool to replace a variables file based on the current environment. That way you can change variables like API hosts for your different environments even though Shopify doesn’t support ENV vars for extensions or theme app blocks yet.

Thank you for your help, but we already have a similar script implemented. However, I’m interested in a native solution from Shopify, not a workaround.

@Liam-Shopify could you help me with this?

Developing a theme extension which uses app owned metaobjects in settings, I’ve also encountered the same problem: the inability to use $app inside metaobject_type.

  • It would be really great to support the $app since it reduces the hardcoding and magic numbers:
{% schema %}
{
  "name": "App block",
  "target": "section",
  "enabled_on": {
    "templates": ["collection", "page", "index"]
  },
  "settings": [
    {
      "type": "metaobject",
      "id": "record",
      "label": "Metaobject label",
      "metaobject_type": "$app:record"
    }
  ]
}
{% endschema %}
  • Or allow the access to app metafields in the metaobject_type {{ app.metafields.config.app_id }}(where app_id has the actual app id):
{% schema %}
{
  "name": "App block",
  "target": "section",
  "enabled_on": {
    "templates": ["collection", "page", "index"]
  },
  "settings": [
    {
      "type": "metaobject",
      "id": "record",
      "label": "Metaobject label",
       "metaobject_type": "app--{{ app.metafields.config.app_id }}--record"
    }
  ]
}
{% endschema %}

@Dylan Thank you for creating and sharing the tool, I will definitely try it out.

@Dylan I checked the envify tool and it seems to generate JS/TS files using the environment variables.

Is it possible to use the tool to replace the app id APP_ID required in the theme extension app block schema? Thank you!

{% schema %}
{
  "name": "App block",
  "target": "section",
  "enabled_on": {
    "templates": ["collection", "page", "index"]
  },
  "settings": [
    {
      "type": "metaobject",
      "id": "record",
      "label": "Metaobject label",
      "metaobject_type": "app--APP_ID--record"
    }
  ]
}
{% endschema %}