Creating a new Editor in Sitecore

There are a lot of neat tricks you can do in Sitecore to make a content editor’s life easier.  In this post I’ll cover creating a custom editor as an alternate way to present data.  We here at HI have used this successfully in the past to give content authors a preview on how their changes may affect a process or to expose data and relationships that may not be present on the rendered site.
The first thing you’ll want to do is create the editor page in your solution.  In my case I’ve added TestEditor.aspx.
Once this is complete you’ll want to switch to the core database and create a new editor item of type/sitecore/templates/Sitecore Client/Content editor/Editor in /sitecore/content/Applications/Content Editor/Editors.  You have the ability (and are strongly encouraged) to create a folder in here to keep your new editors grouped together.
DJSEditor02
This new item only has a couple of fields we’ll need to fill out.  The important one is the url field.  This should point to your custom editor page you created earlier, in my case “/Editor/TestEditor.aspx”.
DJSEditor03
With our editor page created and associated with a Sitecore editor it’s time to switch back to the master database.  The next step will be to assign this editor to different items.  You can either assign this directly to a content item or, as I will do in this example, to the standard values of a template.  Let’s navigate to the standard values (tip: selecting an item in Rocks and pressing ctrl + t will take you to the template).
Which editors are present are managed by the __Editors field of the Appearance section, you’ll need to show standard fields to find it by default.  Using rocks you can add these by right clicking and selecting “Standard Fields”.
DJSEditor04
Now let’s find the __Editors field and add our editor.  Save this and in the Sitecore Content Editor navigate to an item based on this template.  You should be greeted with a new Editor.
DJSEditor05
There we go we have a new editor up and running.  When this editor page loads, Sitecore is kind enough to provide a lot of information about the selected item in the query string.  I’ll provide some code below as a starting point for loading this in case you haven’t dealt with that before.
Please keep in mind, creating an editor should compliment what Sitecore already provides with the page editor rather than attempt to replace it or allow a better editing experience for Sitecore items that may not lend themselves well to the page editor (i.e. they have now presentation).
At this point you should have everything you need to implement your own editor.  Good luck.
Sample code:
public partial class TestEditor : System . Web. UI .Page
     {
            protected string OutputData { get ; private set; }

            protected void Page_Load( object sender , EventArgs e )
           {
                 Sitecore .Security . Accounts. User user = Sitecore .Context . User;

                 if (user == null )
                {
                      HttpContext .Current . Response. StatusCode = 404 ;
                      HttpContext .Current . Response. End ();
                }

                 ID id ;
                 if (! Sitecore. Data .ID . TryParse( Request .QueryString [ "id"], out id ))
                {
                      throw new Exception( "Panic!" );
                }

                 var database = Sitecore .Configuration . Factory. GetDatabase (Request . QueryString[ "database" ]);
                 if (database == null )
                {
                      throw new Exception( "Panic!" );
                }

                 Language language ;
                 if (! Language. TryParse (Request . QueryString[ "language" ], out language ))
                {
                      language = LanguageManager . DefaultLanguage;
                }

                 Sitecore .Data . Version version ;
                 if (! Sitecore. Data .Version . TryParse( Request .QueryString [ "version"], out version ))
                {
                      version = new Sitecore .Data . Version( 1 );
                }

                 var item = database .GetItem ( id, language , version );
                 if (item == null )
                {
                      throw new Exception( "Panic!" );
                }

                 var itemAccess = new ItemAccess ( item);
                 if (! itemAccess .CanRead ())
                {
                      HttpContext .Current . Response. StatusCode = 401 ;
                      HttpContext .Current . Response. End ();
                }

                 OutputData = item. Name ;
           }
     }

Advertisements

One Response to “Creating a new Editor in Sitecore”

  1. Switching things up with the Sitecore Switcher | Horizontal Integration Says:

    […] nifty idea would be tie this into a custom editor that the content author’s could use to preview their content under specific conditions. […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: