Add CurrentThemeId into Body Css Classes

Hi,
Can anybody help me to add active theme id as <html> or <body> CSS class?
I need to write some styles and need different attributes for some themes.

For example when using “dark-theme”:

<html class="desktop-view not-mobile-device text-size-normal dark-theme">

We don’t use the name as an ID, just a number. You can find a theme’s ID by looking at the URL when you’re customizing a theme in the admin panel… for example https://forum.example.come/admin/customize/themes/140

If you can get by with the ID and not the name, this would be a quick way to do it (added to your theme/component’s head file):

<script type="text/discourse-plugin" version="0.8">
  var themeSelector = require('discourse/lib/theme-selector');
  document.querySelector("body").classList.add("theme-id-" + themeSelector.currentThemeId())
</script>

You could also find the theme name by ID, but it would take a little more work.

2 Likes

Thanks, Kris, @awesomerobot
Is there any document for discourse plugin and related libs methods?

I found this but it seems not to include all libs and methods:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.