How are theme setting fields created?

AI-generated summary

The discussion revolves around creating theme settings in Discourse themes. Biscuit asks how to create theme settings when developing a custom theme, noting that imported themes include a YML file that defines these settings. tshenry directs them to a guide on adding settings to themes and clarifies that GitHub isn’t required, recommending the Discourse Theme CLI as a helpful tool. sarahann then asks how to access theme settings in JavaScript, initially encountering an error due to incorrect variable name and file placement. tshenry corrects that the variable is settings, not themeSettings, and sarahann confirms the issue was resolved after adjusting both the variable and file location.

When you import the theme below from Github, “theme settings” appear set under Customize > Theme > Theme_Name.

The Github files include a YML file with the theme settings inside it. The “Import theme” process presumably uses that YML file to make the setting fields appear. But, when I’m writing my own theme (not plugin), how do I create theme settings / parameters like this?

This should be what you are looking for :slightly_smiling_face:: Add settings to your Discourse theme

How did I miss that topic!

Looks like it can’t be done via the interface and requires the files to be placed on Github. Never posted on Github before, so will have to give it a try, to test myself.

Thank you.

No problem :slightly_smiling_face:

You don’t technically need to do anything on GitHub, the Install the Discourse Theme CLI console app to help you build themes is really all you need to get started. It’s an extremely handy tool and easy to set up. I highly recommend giving it a try!

Does anyone know how one would access variables in the theme settings in Javsscript?

<script type="text/discourse-plugin" version="0.8.13">
    console.log(themeSettings.myvalue); 
</script>

I keep getting “themesettings is not defined” in the dev tools

You almost had it. It’s actually just settings not themeSettings :slight_smile:

Thank you @tshenry! I also had it in the wrong file.

My code was in /common/header.html instead of /common/head_tag.html

Thank you for your help! :slight_smile: