Sitecore Gutter Icon to Indicate an Item is a Page

Sitecore’s flexibility allows developers to truly extend it beyond its features that come out of the box. One such extension point is creating a custom icon in the gutter of the content tree. Inspired by a post by Dan Solovay, I’ve decided to create my own custom gutter icon to indicate if a data item is a page.

The reason I decided to create this icon was to help identify to content editors which items in the tree are pages (and thus have URLs represented by their path) vs. which items are merely just data items to store data. The code is quite simple, and the icon and tooltip are overridable via two custom Sitecore settings.

Features:

  • Visually indicates what data items have a layout set.
  • Configurable icon and hover tooltip.
  • Clicking the icon opens the presentation details pop-up.

The Code

[csharp]

using Sitecore;
using Sitecore.Configuration;
using Sitecore.Data.Items;
using Sitecore.Shell.Applications.ContentEditor.Gutters;

namespace CustomGutters
{
public class PageGutterRenderer : GutterRenderer
{

protected override GutterIconDescriptor GetIconDescriptor(Item item)
{
if (string.IsNullOrEmpty(item[FieldIDs.LayoutField]))
{
return null;
}

string iconPath = Settings.GetSetting("PageGutter.Icon");

if(string.IsNullOrEmpty(iconPath))
{
iconPath = "People/32×32/monitor2.png";
}

string iconTooltip = Settings.GetSetting("PageGutter.Tooltip");

if (string.IsNullOrEmpty(iconTooltip))
{
iconTooltip = "The item is a page.";
}

GutterIconDescriptor gutterIconDescriptor = new GutterIconDescriptor
{
Icon = iconPath,
Tooltip = iconTooltip,
Click = string.Format("item:setlayoutdetails(id={0})", item.ID)
};

return gutterIconDescriptor;
}

}
}

[/csharp]

Overrides

The few lines of code that there are do come with two optional overrides:

To change the icon used in the gutter, create a Sitecore setting named PageGutter.Icon with the path to a Sitecore icon (e.g. “People/32×32/monitor2.png”).

To change the tooltip on the icon, create a Sitecore setting named PageGutter.Tooltip with the desired text (e.g. “The item is a page.”).

Download

You can download the DLL for the compiled code and a Sitecore package which installs a single new gutter item in the core database.

 

Mark Ursino

Mark is Sr. Director at Rightpoint and a Sitecore MVP.

 

One thought on “Sitecore Gutter Icon to Indicate an Item is a Page

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.