https://discord.umbraco.com logo
#help-with-umbraco
Dynamic RTE stylesheet
# help-with-umbraco
j

Jamie T

02/07/2024, 3:22 PM
Hi all, we are creating a multi-tenant solution and having a play with the RTE styles, but ideally we would like different styles depending on the tenant you are editing content for. As you set the stylesheet file on the data type it's set for everyone. Any ideas how we can make this a little more dynamic ? Or any other ideas ?
k

krebil

02/08/2024, 9:11 AM
Maybe you can tap into or override these controllers: https://github.com/umbraco/Umbraco-CMS/blob/7046c3585b65b0fb3e6d87ad640035f2be7f3b66/src/Umbraco.Web.BackOffice/Controllers/StylesheetController.cs#L29 GetRulesByName is called when a RTE has a stylesheet attached, so maybe you can circumvent the default behavior when a specific file name is sent. https://github.com/umbraco/Umbraco-CMS/blob/7046c3585b65b0fb3e6d87ad640035f2be7f3b66/src/Umbraco.Web.BackOffice/PropertyEditors/RichTextPreValueController.cs#L21 GetConfiguration is called whenever af RTE is loaded in the backoffice. It doesn't contain stylesheet information but it does contain the configuration options in case you want to change those as well.
m

mwillebrands

02/08/2024, 10:56 AM
You can create an RTE profile for each tenant and use that on your RTE field?
That's OOTB functionallity, or are you sharing the same document types across tenants?
j

Jamie T

02/11/2024, 1:32 PM
Yeah we share data types across tenants. The above is interesting, if only I could add a custom data attribute or an extra css selector into the RTE id be able to then use the Rte css to use that to override - but can’t see anything obvious without having to edit Umbraco code which we are trying to avoid especially as with the new back office we’d probably then have to revisit whatever we do here
Reconfiguration is useful if I could override this and know which node is requesting as Tinymce has the ability to set a ‘body_class’ in the config which if I could inject would solve the puzzle
In case anyone wants to do anything similar, this is what I got working. This essentially intercepts the response from
GetConfiguration
and appends the css file we want, it also adds a class to the body tag which will give selector styling options. I get the current node id from the url and pass this to an API call which goes off and finds the theme property. https://cdn.discordapp.com/attachments/1204809287268827166/1208121831014539284/image.png?ex=65e22222&is=65cfad22&hm=5799fd6bda4b3b5fd148c58115ed2ff5ee4e772eefd558ca93f59b3e3dff61ac&