Add support for theme settings

Continuing the discussion from Discourse Tab Bar for Mobile:

One feature that Discourse doesn’t currently offer is the ability for themes to have some sort of settings or variables that would work similar to how site/plugin settings work i.e. theme settings would be defined with default values by theme developers, and then site owners could override those default values and they’d still be able to get new updates for the theme without worrying about losing their configurations.

How should this work?

Obviously this is not complete specifications - this is just a rough idea on how I see this working. I’m keen to hear your ideas and thoughts :slight_smile:

a) For site owners

I think all we need to do here is add a simple button somewhere on the theme page. that navigates to a new route /admin/customize/themes/:theme_id/settings and the new route will display the settings which will look like this:

b) For theme developers

I think a new field next to CSS and HTML fields that lets theme developers type their theme settings in YAML (or JSON?) format should do the job. Mockup:

(Note “help” is the text that will be displayed below the setting that explains what the setting does)

c) Supported data types

I think we should have setting types that support these data types:

Integer
String
Boolean
Enum
List

d) Accessing theme settings in theme JS code

How will theme developers access theme settings in their JS code? I’m thinking something like Discourse.ThemeSettings.theme_setting_01 but this won’t help with naming collision (when two themes have a setting with the same name) which I’m wondering how should be handled? :thinking:

For now that’s all I have. Happy to hear how you see this working :slightly_smiling_face:

cc @sam

13 Likes