Sitecore Tabbed Select a Rendering Dialog

Posted 5/8/2012 by Kacper Chomicz

This post concerns Sitecore 6.5.0 (rev. 111230).

Sitecore Tabbed Select a Rendering Dialog

As part of Cognifide’s new product offering – CaaS – Campaign as a Service we – the .NET team are busy preparing a set of Sitecore components that will allow for quick, cost effective creation of web pages. The idea is to have a set of predefined components that will suit most customer needs –  splitters to organize content, navigation elements, forms, polls, content body, title, strapline components and many more just ready to be used Out Of The Box! So far, we've created forty components but got the feedback that it’s starting to be a real pain for authors to use them effectively when creating pages because Sitecore displays all available renderings at once in the Select a Rendering dialog used in the Page Editor mode. There’s no option to, for example, categorize them. Fortunately, we discovered a way to make Sitecore Select Rendering dialog even better than it is and suit our needs.

We all love tabs!

This is how the standard rendering selection windows looks like:

Sitecore - standard Select Rendering dialog

Typically, the window would be much smaller with additional scrollbars making the editor's life just a bit harder than it already is. That’s definitely not the kind of Author Experience we want to give our clients. However, there is a simple way to make that selector look clean and not overwhelming – i.e. by adding tabs and organizing components in a logical manner. Unfortunately, this isn’t possible without modifying the Sitecore Select a Rendering dialog, which is exactly what we will do now.

Let’s go bottom up – the image below shows you how the enhanced version of the Selector window looks like. Before you ask if you can get to see it in action, let me say YES, you can download a Sitecore package with Cognifide's Tabbed Rendering Selector and install it using the Sitecore Installation Wizard to enable this functionality on your instance. Read on if you want to know how this dialog works and what changes in the code were necessary to display tabs.

 Sitecore - Tabbed Select Rendering dialog
As you can see this dialog looks more friendlier than the standard version, with components organized in tabs and only few displayed concurrently for authors. How do those tabs work? In the simplest way – using folders under the Sublayouts folder! Components are grouped by parent folder and those folders can be sorted using standard Sitecore sorting and of course everything else, works just as you would expect them to normally work on your Sitecore CMS! This is the structure that defines the tabs for the above window:

Folder Structure defining Tabs in Tabbed Rendering Selector
 Folders under the Sublayouts folder correspond to tabs in the Selector window.

Creating a custom dialog

The first thing to do is to locate the xml control that needs to be changed. Don't worry, it really is an easy task – just copy the control name from the dialog window url (http://sitecore_instance.com/sitecore/shell/default.aspx?xmlcontrol=Sitecore.Shell.Applications.Dialogs.SelectRendering&...) and search /sitecore/shell/ directory in the web app folder for the file containing the control name (in this case SelectRendering.xml). Copy the file to sitecore/shell/override directory and change it as follows:

  1. Change the CodeBeside node to point to your custom class.
  2. Add Tabstrip node just after the “Renderings” Scrollbox <Tabstrip ID="Tabs" Width="100%" Height="100%"/>
Now the fun part begins – changing the code file.
Unfortunately, you will need some help from Reflector or dotPeek because it’s not possible to just inherit the base class in this case – you will need to copy some private methods. I chose the easiest approach – I copied the whole content of the Sitecore.Shell.Applications.Dialogs.SelectRendering.SelectRenderingForm from the Sitecore.Client library to my custom class. Of course, you could inherit from the SelectRenderingForm class and just copy the methods that are private and actually used.

First step is to add the definition of the Tabstrip control added previously in the XML file:
protected Tabstrip Tabs;
Then update the OnLoad method (changes marked with comments):
protected override void OnLoad(EventArgs e)
{
    Assert.ArgumentNotNull((object)e, "e");
    base.OnLoad(e);
    if (Context.ClientPage.IsEvent)
        return;
    IsOpenPropertiesChecked = Registry.GetBool("/Current_User/SelectRendering/IsOpenPropertiesChecked");
    SelectRenderingOptions renderingOptions = SelectItemOptions.Parse();

    if (renderingOptions.ShowOpenProperties)
    {
        OpenPropertiesBorder.Visible = true;
        OpenProperties.Checked = IsOpenPropertiesChecked;
    }
    if (renderingOptions.ShowPlaceholderName)
    {
        PlaceholderNameBorder.Visible = true;
        PlaceholderName.Value = renderingOptions.PlaceholderName;
    }
    if (!renderingOptions.ShowTree)
    {
        TreeviewContainer.Class = string.Empty;
        TreeviewContainer.Visible = false;
        TreeSplitter.Visible = false;
        GridPanel gridPanel = TreeviewContainer.Parent as GridPanel;
        if (gridPanel != null)
        {
            gridPanel.SetExtensibleProperty(TreeviewContainer, "class",
                                            "scDisplayNone");
        }

        //new code
        var gruppedSublayouts = renderingOptions.Items.GroupBy(i => i.Parent.Name);

        //Add new tab for each folder
        foreach (IGrouping gruppedSublayout in gruppedSublayouts)
        {
            var newTab = new Tab();
            newTab.Header = gruppedSublayout.Key;
            var newScrollbox = new Scrollbox();
            newScrollbox.Class = "scScrollbox scFixSize scFixSize4";
            newScrollbox.Background = "white";
            newScrollbox.Padding = "0px";
            newScrollbox.Width = new Unit(100, UnitType.Percentage);
            newScrollbox.Height = new Unit(100, UnitType.Percentage);
            newScrollbox.InnerHtml = RenderPreviews(gruppedSublayout);
            newTab.Controls.Add(newScrollbox);
            Tabs.Controls.Add(newTab);
        }

        gridPanel = Renderings.Parent as GridPanel;
        if (gridPanel != null)
        {
            gridPanel.SetExtensibleProperty(Renderings, "class",
                                            "scDisplayNone");
        }
    }
    else
    {
        var gridPanel = Renderings.Parent as GridPanel;
        if (gridPanel != null)
        {
            gridPanel.SetExtensibleProperty(Tabs, "class",
                                            "scDisplayNone");
        }
    }
    //end of new code
    SetOpenPropertiesState(renderingOptions.SelectedItem);
}

  Compile the code and you should have a brand new tabbed Rendering selector available on you Sitecore instance. If you don’t want to get your hands dirty ;) then, just install the package and enjoy the functionality without writing a single line of code. Or download the source code and play with it if you want more control over the new Dialog.

Download Tabbed Rendering Selector source

Download Tabbed Rendering Selector package

to be used with Installation Wizard from Sitecore Desktop


If you have any suggestions or questions or if there are other dialogs that could use a little tweaking don’t hesitate to comment.
comments powered by Disqus

Kacper Chomicz

Software Engineer

Archive