Global theme settings

AI-generated summary

The discussion revolves around global theme settings in Discourse. Vaping_Community asks about applying global CSS and HTML settings across multiple themes. ZackFea explains that Theme Components can be used for this purpose, allowing shared elements like CSS and HTML to be included in multiple themes. ZackFea provides an example: creating a component theme (e.g., mySpecialHeader) with shared code, then including it in specific themes (e.g., dark and light). This approach also supports Sass variables with !default flags, enabling theme-specific overrides. Vaping_Community appreciates the explanation and the link to a guide on core variables here.

I love the ability to theme discourse and it works really well for individual themes but I feel like global settings for /head / CSS etc that would apply to all themes would make things so much easier when trying to manage multiple themes.

Is this possible?

That is what the Theme Components are for. Add a general theme as compoment to your specific themes and do the general things inside the component. You can use this to override parts of existing themes as well.

10 Likes

Have you got an example of how that works please, I don’t fully understand what you mean, thanks

1 Like

Ok let me say you got a dark and a light theme and you want to add a custom html header and little bit css to both.

So you create a new theme, name it as you want, i will call it mySpecialHeader. Add your custom html and css to this.
Now edit your dark theme, check the “Theme include other child themes”. See screenshot below.

Select you “mySpecialHeader” in the new dropdwon and add it. Repeat this for light theme. That it, your done.

Pro Tipp: As Discourse uses SaSS for css, you can use sass variables with the !default flag and overwrite them in your light or dark theme.

Example:
To mySpecialHeader CSS I add a var for background-color:

$background-color: rgba(210,210,210,0.9) !default;
#mySpecialHeader {
    background-color: $background-color;
}

As this white color and in my dark theme I want a black color, I do override it in dark theme by define the variable in the css of my dark theme

$background-color: rgba(19,20,24,0.9);

You can also use theme based variables. @lll did write a awesome wiki post about it

8 Likes

Wow, that is awesome, thanks for clarifying it’s usage and the link to Core Variables, I think I can do it now :+1:

2 Likes