Editor Tabs in Sitecore

February 27, 2011

updated on 8/11/2011 regarding the order of the tabs. specifically to the position of the content tab .

So during the course of developing websites for Sitecore there are a lot of opportunities to create custom functionality. One feature that I like to use is a custom editor tab. If you're unfamiliar with the concept then you've seen them and just didn't notice. If you have a media folder selected you'll see options to "upload" or "upload advanced".

media tab

This is a custom editor tab. Sitecore provides this one out of the box along with many others but occasionally you'll find it advantageous to create your own.

To be clear there are two roads that you can go down with this kind of thing: the Sheer UI road and the aspx road. If you've never done either you may want to start with the aspx road. I say this because you're most likely a typical .NET developer who is accustomed to writing aspx page. To develop a Sheer UI page you'll have to read up on the language specifics that sitecore provides and how to wire it up. You can start in Sitecore's Developer Network (SDN), but you may need to login to view it. One distinct advantage of the Sheer UI approach is that you will be able to tie into the global editor events such as when a user clicks the save button. This can be important because it's more natural behavior for a user to expect to do that. If you have a custom form that will manipulate the selected items data you will notice that the other tabs do not refresh with the new information until you re-select the item in the content tree. This can be counter intuitive for a user and it's best if you keep it simple. When it's time to make your decision keep in mind that if all you're really looking to do is create a custom display of information then an aspx will do the job just fine otherwise if you need some real tie-ins to the event chain you're going to want to use the Sheer UI route. Also to note that an aspx page can be browsed to and if you do have a form on the page and don't handle the security aspect you may leave yourself open to problems. 

Alright back to the tabs. In my example I'm going to be taking the lesser of two roads which is to create an aspx page. I'm going to just display the values that are provided so that you know how to tie into it for whatever use you may have.

1. In Visual Studio you're going to want to create an aspx page that you'll be using in your project. In this case I'll be creating it at /sitecore modules/web/tabs/newtab.aspx. You can really put it anywhere but keep in mind that as you continue to add these pages you'll want to have some organized location for these things to go. Here's the code for the front end of my aspx file.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="newTab.aspx.cs" Inherits="sitecore_modules.Web.Tabs.newTab" %><html xmlns="http://www.w3.org/1999/xhtml"></html>    <head runat="server"></head>        <form id="form1" runat="server">            <div style="padding:30px;">		            <asp:literal runat="server" id="ltlOut"></asp:literal>            </div>        </form></html>

Then here's the code behind:

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace sitecore_modules.Web.Tabs {	public partial class newTab : System.Web.UI.Page {		protected void Page_Load(object sender, EventArgs e) {			//available querystring values for context info (id, language, version, database)			ltlOut.Text = "id: " + Request.QueryString["id"] + "<br/>";			ltlOut.Text += "language: " + Request.QueryString["language"] + "<br/>";			ltlOut.Text += "version: " + Request.QueryString["version"] + "<br/>";			ltlOut.Text += "database: " + Request.QueryString["database"] + "<br/>";		}	}}

2. Now you're going to need to log into Sitecore and change the database you're viewing to Core

3. Open the content editor and browse to /sitecore/content/applications/content editor/editors.

core tree

This is where you create the editor item. Once this is created and the fields are set you will be able to apply it to as many template types as you want.

4. Right-Click and add an item. You'll have to Insert from template. The path to the editor template is /templates/sitecore client/content editor/editor

new tab

5. Now you'll need to setup the fields. You'll need to choose a name, icon and the file path to the aspx or xml control (Sheer UI) you'll be using.

tab fields

6. Now hit save on the item editor and switch the Sitecore database back to master. Browse to your template that you want to set the tab on and if you don't already have a standard values item then create one and select it. You'll want to apply it to the standard values item not the template. Once the standard values item is selected choose the "configure" tab at the top of Sitecore's ribbon and click on the editors button.

add editors

7. Browse down the tree and select the editor from core that you just created.

add editor dialog

8. You've wired up all the relevant parts and now it's time to view what you've got. Browse into your content tree and select an item of the template type you added the editor tab to. You should see something like this:

 tab view

That's it. Not too painful really. So to recap you're going to have to make a choice about what level of functionality you're going to need. If you're just displaying content in a nice way for your editors then you'll be fine with the aspx approach but if you're looking for a complex solution you'll really want to read up on Sitecore's Sheer UI since this will really open up your options. Please let me know what if anything you end up using this for I'd be interested to know.

As a post script there were a few good questions about the order of the editor tabs and whether or not you could put the "Content" tab first. Cedric also mentions in the comments that there is a Sitecore forum post about it. To start, I found where the editor tabs are created by Sitecore. They're in the Sitecore.Client dll in the Sitecore.Shell.Applications.ContentManager.Editor class in the GetEditorTabs method. I've attached a screenshot so you can see what it's doing in that method.

EditorTabs.jpg

First it creates a list to hold the tabs. Next it gets the "Custom" editor tabs and then it gets the "Content" and "Dynamic" tabs last. If you're looking to be able to set the content tab first you're going to ahve to rewrite this class and figure out what's calling it. It's deep in the belly of the beast. Chait Suwannarat was nice enough to pass on the response from Sitecore's support site regarding a possible patch for the class.

Please perform the following steps:

1. Copy the attached Sitecore.Support.339051.dll file into the /bin folder.
2. Replace the following line in the /sitecore/shell/Applications/Content Manager/Default.aspx file:

<sc:CodeBeside runat="server" Type="Sitecore.Shell.Applications.ContentManager.ContentEditorForm,Sitecore.Client"/>

with the following one:

<sc:CodeBeside runat="server" Type="Sitecore.Support.Shell.Applications.ContentManager.CustomizedContentEditorForm,Sitecore.Support.339051"/>

I've looked over the support dll and noticed that it includes three classes including the change noted above for the Editor class. This means there are other dependancies for this class that if you're going to override this you'll need to look into. I'd strongly urge you NOT TO DO THIS unless you really know what you're doing and are willing to take those risks. I'd also hold off since Sitecore will likely release it as a patch in an upcoming release.