Context based CSS in WYSIWYG TinyMCE editor for EPiServer multisite

In multisite scenarios or when you use optimization libraries you’ll need to set the TinyMCE editor css dynamically from the code.

tinymce

Normally you register the editor CSS thru the web configuration:

But sometimes in scenarios where you are using a optimization library like Combres to pack the CSS:s you’ll need to set the CSS programmatically. If you have a multisite scenario you’ll need different CSS for each site.  Thanks to other blogposts I’ve made a variation of a descriptor that works for my solution.

Since I use bootstrap.css I had to put some classes like “container” in the tinyMCE editors body to make bootstrap work. I also put the site name in the body class and the property name. Finally I add a tinymce.css where I can put custom editor css and editor styles, styleswith help of EditMenuTitle and EditMenuName (which won’t work if you don’t have a stop “;”)

Because the WYSIWYG uses an iframe, be aware of the column widths will not work, since the editor width is smaller.

Because I want to use this custom change globally i do use EditorDescriptorBehavior.PlaceLast and inherit EditorDescriptor.

The result: Body tag with custom CSS and head with your context based CSS styles.
The result: Body tag with custom CSS and head with your context based CSS styles.

Limitations in UIEditorCssPaths: You can’t have absolute urls nor non file urls (eg not without a file extention)

More reading:

Like it? please up vote
1