A space to discuss online store customization, theme development, and Liquid templating.
How to add dynamic options for a selection to the theme app blocks?
The metafields are perfect for this but Shopify Cli does not allow to publish of such code
{
"type": "radio",
"id": "logo_aligment",
"label": "Logo alignment",
"options": "{{ app.metafields.myapp.some_select.value }}"
}
]
}
{% endschema %}
ello there
To add dynamic options for a selection to the theme app blocks, you can use JavaScript to fetch the data from the metafields and populate the options for the selection field.
First, add the selection field to your schema as follows:
{ "type": "select", "id": "my_select", "label": "My Select", "options": [] }
Then, in your JavaScript code, fetch the dynamic options from the metafields and populate them in the selection field as follows:
const mySelectField = document.querySelector('#my_select');
const options = "{{ app.metafields.myapp.some_select.value }}";
const optionsArray = options.split(',');
optionsArray.forEach(option => {
const newOption = document.createElement('option');
newOption.value = option;
newOption.text = option;
mySelectField.add(newOption);
});
Thank you for your reply but Shopify CLI does not allow to publish of such code
[blocks/conditional-app-block.liquid] Invalid tag 'schema': settings: with id="my_select" options can't be empty
Looks like Shopify dev team do everything to cut flexibility and force to tell clients change platform to another.