How to access theme component setting from another theme component

This is technically feasible, but as David's stated below, please don't use it

I took a look because it’s quite an interesting question! :+1:

There is a place in discourse/lib/theme-settings-store where the theme settings are stored and exported functions such as getObjectForTheme or getSetting. can be used.

You can retrieve the value of a setting for any theme component as long as you have its ID.
However, I couldn’t find an easy way to retrieve the translation ID ↔ name mapping.

That said, you could do the following trick:

// Retrieves from <link> tags the theme name <-> id mapping for the active theme components
const themesComponents = Array.from(
  document.querySelectorAll("link[data-theme-name]")
).reduce((acc, link) => {
  acc[link.dataset.themeName] = parseInt(link.dataset.themeId, 10);
  return acc;
}, {});

// Gets the theme id based on its component name
const themeId = themesComponents["discotoc"];

// Gets all the settings
const themeSettings = getObjectForTheme(themeId);

// Gets a specific setting
const themeSetting = getSetting(themeId, "anchor_icon");

image

I’m unsure that’s the best reliable way; some helpers would be nice if it does not exist.