# Sélecteur de données pour les thèmes

**URL:** <https://meta.discourse.org/t/data-selector-for-themes/152019>\
**Category:** Development\
**Created:** [Mai 19, 2020, 11:51 UTC](https://meta.discourse.org/t/data-selector-for-themes/152019 "2020-05-19T23:51:50Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)\
**Post date:** [Mai 20, 2020, 8:11 UTC](https://meta.discourse.org/t/data-selector-for-themes/152019/6 "2020-05-20T08:11:27Z")

</div>

Si vous ajoutez ceci à l’onglet en-tête de votre composant de thème

```markdown
<script type="text/discourse-plugin" version="0.8">
  const themeSelector = require('discourse/lib/theme-selector');
  const currentThemeId = themeSelector.currentThemeId();
  document.body.dataset.themeId = currentThemeId;
</script>

```

Cela ajoutera un attribut `data-theme-id` à la balise `<body>` que vous pourrez utiliser comme suit :

```css
[data-theme-id="1"] {
  // CSS du thème clair
}

[data-theme-id="2"] {
  // CSS du thème sombre
}

```

---

_[View the full topic](https://meta.discourse.org/t/data-selector-for-themes/152019)._
