Custom attributes in settings_data.json disappear

Georgi_Tenev
New Member
2 0 1

Hi all

I've added some attributes to the settings_data.json file which I use in my liquid templates - to avoid code duplication, etc.

 "alarmsyst_show_products_on_top_level_category": [
      "\/collections\/bluetooth-komplekti-za-kola",
      "\/collections\/dnevni-svetlini-drl"
    ],
    "alarmsyst_show_no_price": [
      [
        "персонализация"
      ]
    ],
    "alarmsyst_hide_add_to_cart": true,
    "alarmsyst_hide_subcollections": true,
    "alarmsyst_extra_payment_for_alarms": "За функциите, отбелязани със звездичка (*), е възможно да се наложи допълнително заплащане.",
    "alarmsyst_avtokasko_promotion_alarms": "ОТСТЪПКА 10% ПРИ СКЛЮЧВАНЕ НА ЗАСТРАХОВКА \"АВТОКАСКО\"",

It all works correctly (i.e. I can access these settings from my liquid code.

However if the shop owner goes to the admin panel -> Online store -> then clicks Customize theme and say, changes the announcament on the top of the site via the theme editor and presses Save, my attributes in the settings_data.json are removed. It's as if shopify internally has a copy of the file which doesn't have my attributes and merges it with the new changes the shop owner has made.

This is quite annoying since I have to go back and re-add the attributes every time the site announcement is changed.

Any ideas? Thanks a lot!

Jason
Shopify Expert
10037 119 1873

It might be annoying, but that result is to be expected. That file is generated after any change is made via the Theme Customizer. All the data within the settings json file is generated from the theme settings for that theme.

If you want the settings to remain in place, add the relavant settings into the schema or hard code the values into a snippet for later use.

A good starting place for learning more about the theme settings and schema is here:
https://help.shopify.com/themes/development/theme-editor/settings-schema

It also looks like you're adding some values that could be language/translation related. Those might be better for the language settings instead.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Superfunk
Shopify Partner
16 1 1

In order to avoid that you could declare the attributes directly in the file Config/settings_schema.json.

These are the theme options -> Config/settings_schema.json

These are the values assigned to the already declared theme options -> Config/settings_data.json

This could be what you declare at Config/settings_schema.json

 

...
{
    "name": "Promo",
    "settings": [
      {
        "type": "text",
        "id": "sale_name",
        "label": "Sale name",
        "default": "Some Sale"
      },
      {
        "type": "text",
        "id": "sale_banner",
        "label": "Sale banner",
        "default": "null"
      }
    ]
  }
...

 

 

This could be what you declare at Config/settings_data.json

 

...
"sale_name": "Big Sale",
"sale_banner": "https://cdn.shopify.com/s/files/1/0443/9359/5031/files/banner.png?v=1610649211",
...

 

 

And that way you should be able to keep the values you store at settings_data.json 

0 Likes