You have several options when customizing the Sitecore Rich Text Editor. It’s simple to setup custom sets of buttons and assign to different templates. If you are unsure on doing this I’d suggest googling ‘sitecore custom rich text editor’. This post details how to use the ‘Html Editor Configuration Type’ items.
Within the application there are various global settings which configure things like default tags to use for line breaks, which profile to use as default and a few more:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<!-- HTML EDITOR DEFAULT CONFIGURATION TYPE Specifies the type responsible for setting up the rich text editor. Can be overriden at profile level. Must inherit from Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client. Default value: Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client --> <setting name="HtmlEditor.DefaultConfigurationType" value="Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client" /> <!-- HTML EDITOR DEFAULT PROFILE Path to the default html editor profile. Default value: /sitecore/system/Settings/Html Editor Profiles/Rich Text Default --> <setting name="HtmlEditor.DefaultProfile" value="/sitecore/system/Settings/Html Editor Profiles/Rich Text Default" /> <!-- HTML EDITOR LINE BREAK Specifies the tag that the HTML editor inserts on Enter. Values can be "br", "div" and "p". --> <setting name="HtmlEditor.LineBreak" value="p" /> <!-- HTML EDITOR REMOVE SCRIPTS If true, the rich text editor removes script tags from RTE field values before saving. Setting the value to true reduces the potential for cross-site scripting and other script-related issues. Default value: true --> <setting name="HtmlEditor.RemoveScripts" value="true" /> <!-- HTML EDITOR SUPPORT WEB CONTROLS Indicates if the Html Editor supports web controls. If true, Web Controls are shown as yellow boxes. Default value: true --> <setting name="HtmlEditor.SupportWebControls" value="true" /> <!-- HTML EDITOR VALIDATOR SERVICE URL Specifies the url that validates XHtml. --> <setting name="HtmlEditor.ValidatorServiceUrl" value="http://validator.w3.org/check" /> |
The problem we ran into was that for certain rich-text-editors we wanted the line breaks to be br tags, elsewhere p tags. This ruled out the setting above.
One hidden feature which is very useful is the ability to setup different configurations for each rte. If you look in the folder in core ‘/sitecore/system/Settings/Html Editor Profiles/Rich Text Default’ you will see an item of type ‘/sitecore/templates/System/Html Editor Profiles/Html Editor Configuration Type’. Here you can define a type, the default mapped to ‘Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client’
If you need to setup specific RTE’s to use br tags instead of p tags:
- Setup your custom RTE profile in core
- Create an item of type ‘/sitecore/templates/System/Html Editor Profiles/Html Editor Configuration Type’ called ‘Configuration Type’
- Create a new class which inherits from ‘Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration’
- Update the ‘Configuration Type’ item to reference your new class
- Override the methods you need – I found simply overriding SetupEditor was enough (see below).
An example of the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
using Sitecore.Data.Items; using Sitecore.Shell.Controls.RichTextEditor; using Telerik.Web.UI; namespace ###.SitecoreCustom { public class CustomRichTextEditor : EditorConfiguration { public CustomRichTextEditor(Item profile) : base(profile) { } protected override void SetupEditor() { base.SetupEditor(); Editor.NewLineMode = EditorNewLineModes.Br; } } } |