"MySpace" the Content Editor - Customizing the Content Editor via the Rules Engine Part 3 - File Mapping

Wednesday, March 15, 2017 @ 01:30
MySpace Image

By: Eric Stafford, Sitecore Developer – Let's pretend I inherited a very old Sitecore implementation that was developed in the dark ages back in 2010 using Sitecore version 6.4. Before version 7 and the renaissance, the history books tell us that this time period was very dangerous, the Page Editor was largely ignored, template and field proliferation was widespread and anarchy reigned supreme.

Early in development on this site, a "Content Block" template was created. It was basic, it had three fields: Title, Summary and Link. As things progressed, requirements changed and features were added, a developer missed that perfect time to split this component up and this poor "Content Block" ended up with 14 fields.

Template: Content Block
Section: Content
Fields: Title, Subtitle, Summary, Abstract, Footnote, Link, Link2
Section: Media
Fields: Image, Icon, Video, Video Placeholder Image
Section: Settings
Fields: Background Color, Image Position, Container Css Class

Today, we all encourage content authors to use the Experience Editor. Luckily for this site, the Experience Editor helps hide the ugliness of the "Content Block". However, the content author working on this site prefers the Content Editor. The content author's current task is editing a "Content Block". The page that this component appears on only utilizes three fields: Title, Summary and Link. Without any customization, this simple content entry task is frustrating and the author isn't happy. Good news! We now have the tools to make this content author's experience better.

Part 1 of this series on customizing the content editor focused on performing actions on fields and sections one at a time. That approach is fine for quick customizations, but with the example above, manually hiding fields and sections can be tedious and time consuming. It would be awesome if we could do this all in one action. One approach we can take is using an XML document to pass in the field and section information.

I chose XML because it's basic and Sitecore comes with the HtmlAgilityPack that makes working with Html/XML very easy. I also wanted to avoid bringing in any other 3rd party assemblies. I did consider other file formats such as YML and might implement that soon.

The XML

Place this file in the root or create a ContentEditorMappings directory and place it there:

Creating the File Mapping Rule Item

Create a new “Map File” action in the element folder (/sitecore/system/Settings/Rules/Definitions/Elements/Customize the Content Editor) created in Part 1.

  • Map File
  • In the Data section -> Text field, add: Map File: [Path,,,Path]
  • In the Script section-> Type field, add the fully qualified name for the action: Paragon.Sc.ContentEditor.Rules.Actions.MapFile,Paragon.Sc.ContentEditor

The File Mapping Action

The Code to Map the XML

I've left out some minor code and I also made a few changes since Part 1. You can download the source code and everything you need to get started from Github.

If you have any questions, comments or suggestions, please feel free to tweet or Skype me.

Haven't read the other chapters?
Part 1 - "MySpace" the Content Editor - Customizing the Content Editor via the Rules Engine
Part 2 - "MySpace" the Content Editor - Customizing the Content Editor via the Rules Engine