The discussion centers around adding custom class attributes to HTML elements in Discourse, particularly for tables and UI components. W.M initially asks how to add a class to a markdown-generated table, but codinghorror clarifies that arbitrary HTML is disallowed for security reasons. david offers a workaround using whitelisted data-theme-* attributes, which can be targeted via CSS — a solution W.M appreciates. Later, sarahann seeks to add classes to the body or admin UI to distinguish between moderators and admins, referencing codinghorror again. cpradio explains that plugins can add classes, either via controllers or by overriding .hbs templates — though the latter requires maintenance. sarahann struggles with .js.es6 and DOM targeting, prompting cpradio to suggest using JavaScript on page load to detect user roles via Discourse.User.current() and dynamically add classes. sarahann finds this helpful but notes JS struggles with persistent admin-page detection. Ultimately, she decides to override the admin wrapper template directly sarahann. The thread highlights the limitations of markdown and themes, and the flexibility (with trade-offs) of plugins and JS for advanced customization.
Generally you either reopen it’s controller which can define a class or if it truly is in the hbs, you can overwrite the hbs file by placing it is the same folder structure in your plugin. Just realize doing that means you have to maintain and copy changes that occur in that file in core.
Hmm maybe its the .js.es6 file extension? To be honest, I have no idea how to go about this.
I’m hoping of a way to distinguishing between mods and admins in the admin portal by adding a class somewhere in the DOM (preferably on the admin-wrapper or body). So that I can trigger a “display: none” on some of the buttons in the admin panel.
Actually, I remember now why I was trying to do this in a plugin and not in javascript. |
In JS its hard to tell when the user is in the admin page. And in the past I have tried to add classes before and I couldn’t find a persistent event so that my JS code would run on every page. api.onpagechange only works when the url changes (not the view).
Thank you for the help!
I guess I’ll overwrite the admin wrapper with my class name in it and see how that goes