# Come accedere all'impostazione del componente tema da un altro componente tema

**URL:** <https://meta.discourse.org/t/how-to-access-theme-component-setting-from-another-theme-component/290303>\
**Category:** Development\
**Created:** [2 Gennaio 2024, 6:58pm UTC](https://meta.discourse.org/t/how-to-access-theme-component-setting-from-another-theme-component/290303 "2024-01-02T18:58:23Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)\
**Post date:** [3 Gennaio 2024, 4:47pm UTC](https://meta.discourse.org/t/how-to-access-theme-component-setting-from-another-theme-component/290303/2 "2024-01-03T16:47:49Z")

</div>

> **Questo è tecnicamente fattibile, ma come indicato da David di seguito, per favore non usarlo**
>
> Ho dato un’occhiata perché è una domanda piuttosto interessante! 👍
> 
> C’è un posto in [`discourse/lib/theme-settings-store`](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/theme-settings-store.js) dove sono memorizzate le impostazioni del tema e si possono usare funzioni di esportazione come `getObjectForTheme` o `getSetting`.  
> Puoi recuperare il valore di un’impostazione per qualsiasi componente del tema, purché tu ne conosca l’ID.  
> Tuttavia, non sono riuscito a trovare un modo semplice per recuperare la mappatura ID traduzione ↔ nome.
> 
> Detto questo, potresti fare il seguente trucco:
> 
> ```js
> // Recupera dai tag <link> la mappatura nome tema <-> ID per i componenti del tema attivi
> const themesComponents = Array.from(
> document.querySelectorAll("link[data-theme-name]")
> ).reduce((acc, link) => {
> acc[link.dataset.themeName] = parseInt(link.dataset.themeId, 10);
> return acc;
> }, {});
> 
> // Ottiene l'ID del tema in base al suo nome componente
> const themeId = themesComponents["discotoc"];
> 
> // Ottiene tutte le impostazioni
> const themeSettings = getObjectForTheme(themeId);
> 
> // Ottiene un'impostazione specifica
> const themeSetting = getSetting(themeId, "anchor_icon");
> 
> ```
> 
> ![image](https://global.discourse-cdn.com/meta/original/4X/1/0/5/10571cc71dadb5bbcd18a1b919d0faeab8612d86.png)
> 
> ![image](https://global.discourse-cdn.com/meta/original/4X/2/8/9/28982b72887d791f54017b374fa19f50619ca287.png)
> 
> ![image](https://global.discourse-cdn.com/meta/original/4X/4/3/0/430079c5de97d84a2d103a248d9fb911cca984d1.png)
> 
> Non sono sicuro che sia il modo più affidabile; sarebbero utili alcuni helper se non esistessero.

---

_[View the full topic](https://meta.discourse.org/t/how-to-access-theme-component-setting-from-another-theme-component/290303)._
