Developers often push aside the rich text editor because we would rather of use separate components with data sources. However, sometimes we need to rely on the rich text editor to empower the content editor to edit more directly or to reduce complexity on the page. We can use snippets to reduce complexity or give the editor more options by inserting some predefined HTML into the rich text editor. In this example, we will learn how to get more out of the rich text editor by changing which editor we use, adding new snippets, and styling the added content.
First we need to switch from the default basic rich text editor to either one of the other existing editors or to a custom editor.
The Rich Text Default view - just the basics:
First we need to switch from the default basic rich text editor to either one of the other existing editors or to a custom editor.
The Rich Text Default view - just the basics:
We can change the default editor on a field-by-field basis. Update the Source Property for the Rich Text field so that it references the specific rich text editor we want to use in the core database:
On your template, enter the item path for the editor of your choice into the source field for the rich text field.
For a site-wide approach, you can change the Sitecore.config file on the setting “HtmlEditor.DefaultProfile” to update all rich text fields by default:
With the updated rich text editor, we can now see our Snippets Option:
Snippets are simply blocks of raw html that can be placed on the page and controlled in the Core database. Once you know what html you need to add, it’s very easy to create a new one in Core by navigating to the Snippets folder within the Html Editor Profile you’re currently using and either adding it via the menu, or by duplicating and modifying an existing snippet.
Once we save our snippet and head back to the Master DB and open the rich text editor, we’ll see our new Fancy Blockquote Snippet!
Clicking on our new snippet will insert it into the text at the cursor location, but currently it isn’t all that fancy:
We can stop here and call it a day but if we want our styling to appear within the editor as we are editing we need to make a final update to the sitecore stylesheet used by the editor.
To make this update we can either edit the default style sheet (modify default.css) or reference our own to include the styling used by your snippets (and anything else you’d like represented). The stylesheet is defined once again in Sitecore.config as “WebStylesheet.”
Once the file is updated you’ll immediately see your classes represented in both the page editor preview as well as the editor:
In the editor:
And that’s it - snippets are an easy way to add some quick and editable html! With the updated stylesheet you can view your content appropriately to get a little more mileage from your rich text fields when you need to use them!
Hi Amy,
ReplyDeleteI'm doing exactly the same as you have mentioned above, except that the quote being inserted has p tags and footer tags inside it.
What I am seeing in the RTE (in some instances - not always) , is that it is reorganizing the mark-up being inserted so that the blockquote tag is around the footer.
Any ideas as to why this might happen?
Thanks,
James.
p tags specifically do some weird stuff by default within the editor - i'd limit these custom snippets to html that isn't going to be hit by the filters (p tags, and depending on your config also script tags) - or- you can also override the methods that do this from Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration - but that involves having a custom configuration for your RTE.
DeleteI have a custom EditorConfiguration where i disabled EditorFilters.ConvertToXhtml but snippets still get code removed or changed. Any idea how to fix with snippets?
DeleteThis comment has been removed by a blog administrator.
ReplyDelete