Content driven classes in the sitecore rich text editor

Here’s a quick tip related to the rich text editor in Sitecore. In 6.4 the telerik rad control was added, via specific style sheets you can expose css classes for the content editor to use.

Mark Stiles has blogged about this here.

These approaches works fine but what if you want the styles to be dynamic ie a content editor can add and remove them?

The solution

  1. You setup some items in your tree which represent CSS classes (name and required styles).
  2. You then create an httpHandler which sets its content type to be CSS.
  3. In your handler you expose all the CSS styles from the tree and render to the output (you may need to explicitly select which db to use in the handler since the requests may not run through all the sitecore pipelines). If needs be you could stream through the styles from the physical existing web stylesheet as well.
  4. You then point the WebStylesheet setting at your new handler.

Remember, you need to include the CSS link tag in your layout which points to your handler otherwise the classes won’t exist in the front end.

Leave a Reply

Your email address will not be published. Required fields are marked *