In een plugin, hoe voegt men per gebruiker CSS toe? Bijvoorbeeld veroorzaakt door een gebruikersinstelling?
Het toevoegen van de stijlen en dergelijke aan elementen/via stylesheets zou globaal zijn, nietwaar?
In a discussion titled “Add per-user CSS in a plugin?” under the Dev category, NateDhaliwal asks how to implement user-specific CSS in a Discourse plugin, such as changing fonts in the Markdown composer based on user settings. Kartoon suggests that per-user theme changes may require assigning users their own themes, while Moin proposes using user groups with CSS classes or browser extensions like Stylus for personalization. NateDhaliwal clarifies that the composer was an example, and the goal is to allow font changes per user. keegan provides a technical pathway: use the plugin API to add a user option field (e.g., composer-custom-font), store it in the UserOption database table, expose it via a user interface connector, and extend the composer to apply the selected font via JavaScript or CSS classes. This approach allows dynamic, user-specific styling without requiring global CSS changes or separate themes.
In een plugin, hoe voegt men per gebruiker CSS toe? Bijvoorbeeld veroorzaakt door een gebruikersinstelling?
Het toevoegen van de stijlen en dergelijke aan elementen/via stylesheets zou globaal zijn, nietwaar?
Wat probeer je te doen? Je kunt dingen zoals de kleur van individuele gebruikersnamen/vermeldingen veranderen, gewoon via de normale themacss. Als je bedoelt, een specifiek deel van een thema veranderen met een schakelaar via de voorkeuren van een specifieke gebruiker, dan geloof ik niet dat je dat zou kunnen doen zonder hen hun eigen thema te geven. Ik ben echter geen expert.
Zoals bijvoorbeeld, een instelling per gebruiker om lettertypen van bepaalde dingen te wijzigen (bijv. de Markdown-editor).
You could offer groups that the user can join and use CSS Classes for Current User's Groups.
Or the user can use a browser plugin to change CSS only for themselves. I use Stylus to customize my experience on Meta.
Was the composer a random example? Or what do you want to offer in addition to “Use monospace font in composer’s Markdown mode,” which can be enabled or disabled in the preferences?
Kinda. I was thinking how the font would be changed per-user.
You can probably achieve this in a plugin by doing something along the lines of:
api.addSaveableUserOptionField("composer-custom-font")UserOption table in the db and the serializer so it can be set