将 CurrentThemeId 添加到 Body CSS 类中

我们不使用名称作为 ID,只使用数字。你可以在管理员面板中自定义主题时查看 URL 来获取主题的 ID,例如 https://forum.example.com/admin/customize/themes/140

如果你可以使用 ID 而无需名称,这是一种快速实现方法(将其添加到你的主题/组件的 head 文件中):

<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>

你也可以通过 ID 查找主题名称,但这需要更多的工作。

2 个赞