A space to discuss online store customization, theme development, and Liquid templating.
Hi all,
I try to adopt the Baseline theme to fit the local regulations and display a link with a popup next to the price in the default product page. Therefor I wanted to add some settings to the product page price block:
{
"sections": {
"main": {
"type": "main-product",
"blocks": {
...
"price": {
"type": "price",
"settings": {
"setting1": 2,
"setting2": "blub"
}
},
...
}
...
}
...
}
}
But when save the file during having "shopify theme dev -e theme-name --theme-editor-sync" running, the "setting1": 2, "setting2": "blub" get deleted immediately.
Just went over all the Shopify Theme documentation, but couldn't find any indication, why this happens.
Is this a theme thing, or is shopify itself doing this?
Hi SaaSQuadrat,
I believe the settings might be getting deleted because the structure is not correct. The settings should be defined within an array and each setting should be an object with its own properties, such as 'type', 'id', 'label', and 'default' - following the pre-existing pattern of how the settings are created. eg, having a setting property of "setting1" will be invalid, as there's only predefined properties that can be used in the array.
Here's an example of how you should structure your settings:
{
"sections": {
"main": {
"type": "main-product",
"blocks": {
"price": {
"type": "price",
"settings": [
{
"type": "text",
"id": "setting1",
"label": "My Setting 1",
"default": "2"
},
{
"type": "text",
"id": "setting2",
"label": "My Setting 2",
"default": "blub"
}
]
}
}
}
}
}
In the above example, 'type' specifies the type of setting (in this case, 'text'), 'id' is a unique identifier for the setting, 'label' is the label for the setting that will be displayed in the theme editor, and 'default' is the default value for the setting.
If you follow this pattern you should see your settings being saved correctly - hope this helps!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Edit: obviously the documentation is wrong. Dawn is doing it different. See more details further down.
Hi Liam,
that's interesting. I also looked into the documentation, which tells the same as you, as expected.
But when I change the template/product.json to "settings": [] I get following error message:
```
$ shopify theme dev --theme-editor-sync -e xyz
...
The local file templates/product.json is different from the remote version in the development theme.
? What would you like to do? (You chose: Keep the local version)
100%
• 17:31:18 ERROR » update templates/product.json:
Invalid settings object for block 'price'. Settings must be an object.
```
This is my file getting the error:
```
```
As you can see, it doesn't complain about the settings object for the title block.
Is this maybe some kind of backwards compatibility mode, for older schema definitions?
I know the Switch Themes Baseline theme I am currently work on, does not comply with all Shopify OS 2.0 requirements till now. Hence, this guess.
Edit:
Hi Liam,
I am afraid the documentation is either wrong, or the Dawn theme magically also does follow the wrong standards and works magically. 😉
This is the top of the current Dawn theme's templates/product.json:
```
```
If this works, the documentation is plain wrong. Sorry.
And I also get the same behavior. Adding a setting in the "price" block settings, saving it updates it and the following get removes it again.
Here a screencast I have recorded with the dawn theme: https://streamable.com/hw9db1
Greets,
Andreas