How to use shop metadata to populate a select setting

Hello all, I’m a bit stuck and surprised this is so challenging.
The goal is to save settings in the admin area, and load them for use in the theme editor app block settings schema via metafields.

1: In the admin area I’m creating a valid json object and saving it as a meta object of type json:

    "namespace": "mynamespace",
    "key": "droplist",
    "ownerId": shopObject.id,
    "type": "json",
    "value": JSON.stringify(droplist_data)

-works fine. data saved.

2: In the liquid area of the app block I’m retrieving it and confirming it’s a json object:

{% assign optionslist = shop.metafields.mynamespace.droplist | json | default: '[]' %}

-works fine, outputs formatted data .

3: In the schema of the app block I’m trying to insert it as the options array. (this is how the Dev Assistant says it should work) but I’m having no success.

{
    "type": "select",
    "id": "locations",
    "label": "t:blocks.locations.settings.set_loc.label",
    "options": {{ optionslist }},
    "default": "US"
 },

Error:

Invalid tag 'schema': Unable to parse 'schema' content

I’ve tried a number of things but always get the "Unable to parse 'schema' content" error.
What’s the proper method for doing this?

How would I dynamically create multiple droplists?
Perhaps this an issue with the schema validator? Can that be overridden to test?

Thanks in advance, Ski_Bot

Could you please confirm the options provided as below?

Also, please check if the dropdown works with hardcoded values.

{
  "type": "select",
  "id": "sizes",
  "label": "Sizes",
  "options": [
    {
      "value": "xs",
      "label": "X-small"
    },
    {
      "value": "s",
      "label": "Small"
    },
    {
      "value": "m",
      "label": "Medium"
    },
    {
      "value": "l",
      "label": "Large"
    },
    {
      "value": "xl",
      "label": "X-large"
    },
    {
      "value": "xxl",
      "label": "XX-large"
    }
  ],
  "default": "m"
}

Thanks for the reply. Yes, hard coded values work fine, the select element you provided also works fine.

1 Like

Can I mark this as solved @Ski_Bot ?

Liam, Please do not. This is still an issue. I really need to determine if this is even possible on the platform. If so I’m still looking for a solution, If not my app is dead and I’ve wasted months.

To reiterate the basic issue: Can a select element be dynamically created in an app-block schema using shop metafield data?

Thanks.

My mistake @Ski_Bot - let me connect with our internal teams to confirm this.

1 Like

Setting values do not support Liquid logic. Please refer to the documentation for more details.

Thanks @AMaL, that’s a helpful page. As you said, according to the documentation: Settings values can't contain Liquid logic.

That’s bad news for my App, but I’ve come too far to give it all up so easily. According to the Documentation above, the schema json check can be bypassed. but it’s not recommended.

Unfortunately the {% # theme-check-disable %} tag from the documentation seems to have no effect on my issue, still getting the error, but still trying to make that work. Maybe it’s intended for a different context?
I’ve also had no luck trying to bring in the entire schema instead of altering a section. It seems pretty immutable.

@Liam-Shopify Is there any advice from the internal team on a workable route to reach the original goal? How would you handle a requirement like this?

Also: Please be sure to fix the hallucinating Dev Assistant. It seems to be giving out bad advice.

Hi - the .dev assistant is primarily trained for generating queries and help for GraphQL (although it has access to the full .dev docs), but I’ll reach out to that team to flag this.