Insert Sitecore related content directly into the RTE

What I want to achieve with this post is give the editors the possibility of inserting related content from other pages into their current Rich Text Editor. They could insert related content from some selected fields in another pages or render some spots so that they would present a page somewhat like this :demospot

I am still working on mastering the art of explaining in text so  I will try to make it as short and concise as possible. Green text comes from a ”Page 1”  and gray text is related content inserted from ”Page 2” . So on “Page 1” we will not have to have a RTE field, then a related content selector and another RTE field. There will be just one RTE field.

The solution is to insert a custom snippet in the RTE which then I will capture in the RenderField Pipeline and replace it with the markup I want.

The snippet I created is in the Core db and has this value:

value

This means that the editor will need to know the Page Item ID from where the gray text will be rendered from. I selected this XML formatting for ease of explanation but it can be anything you can later identify and extract from the text.

Then I created my own Pipeline step (RenderSublayout) and inserted it right after the ”GetTextFieldValue” pipeline step in the RenderField pipeline.

In this class I am finding all the snippets  that I want to replace with my own markup and assemble them in a list of RelatedContentSpotSnippets. This way the editor can add more of these snippets in the same RTE and they will be replaced with the correct markup.

This approach can be modified so that instead of inserting the ItemId the editor would insert the path to the spot. Also one may insert an image representing the spot so that the editor has an idea on how the page woud look.

The RenderUserControlService looks like this:

I think this functionality can be extended depending on the requirements but at least I consider it to be a start for someone who wants to achieve something like this.

Avatar photo

Alin Parjolea

System Developer at Pentia. I have been involved in small and large scale projects using Sitecore and .Net for the last 4 years. I am Sitecore certified developer since 2009. I have a Master degree in Computer Science from University of Southern Denmark. More detailed info about me can be found on my Facebook and LinkedIn pages.