Category Archives: Productivity

Update layout data source references when copying a Sitecore item

Creating a page with faulty data source references

Every once in a while a content editor walks up to me to tell me that a new page does not show the content as expected. When a content editor copies an item to create a new page this usually means the layout references the data sources of the original. When you copy a page, the page is copied together with all underlying item, but the copied item still references the data sources as defined in the source item.

Correcting the data source references when copying a page

Fortunately there is an easy solution to this problem. Jan Hebnes mentions a LayoutDataSourceReferenceUpdater in a blog post some years ago (
This piece of code is registered as an item:saved event. When you copy an item all references in the layout field that point to a data source that is a descendant of the item copied are updated to point to the equivalent item under the copied item. I have modified Jan’s gist ( to also support the final layout field.

If you have content editors that sometimes work in the content editor, this might save them (and yourself) a lot of work.

Check out the modified source here:
Available on NuGet:

Restore multiple items from sitecore recycle bin using the API

Have you ever messed up and couldn’t be bothered cleaning up in the ‘accepted’ way? I accidentally removed a large number of items from the sitecore media library. Restore the database? Maybe there is a faster way. Fortunately sitecore comes with a recycle bin. Unfortunately the recycle bin is not meant for cleaning up dumb mistakes.

When you delete one item that has subitems, all is great. The deleted item shows up in the recycle bin. When you restore the item, all subitems are restored as well. When the items are deleted one by one, they have to be restored one by one. Fortunately in the sitecore recycle bin you can select multiple items on a page to restore. Unfortunately this is limited to 15 items per page.

sitecore recycle bin

I had to restore 300+ items. To restore these by hand would mean scrolling through numerous pages to restore the items, 15 items at the time. Fortunately the sitecore API provides simple access to the recycle bin. This code on stackoverflow saved me from going through all the items by hand. I modified it so I could restore all items deleted after a certain date where the path started with a certain prefix.

The code to restore items from recycle bin using the sitecore API

using (new SecurityDisabler())
    DateTime archiveDate = new DateTime(2015, 9, 8);
    string pathPrefix = "/sitecore/media library";

    // get the recyclebin for the master database
    Sitecore.Data.Archiving.Archive archive = Sitecore.Data.Database.GetDatabase("master").Archives["recyclebin"];

    // get as many deleted items as possible 
    // where the archived date is after a given date 
    // and the item path starts with a given path
    var itemsRemovedAfterSomeDate =
        archive.GetEntries(0, int.MaxValue)
                .Where(entry => 
                    entry.ArchiveDate > archiveDate && 

    foreach (var itemRemoved in itemsRemovedAfterSomeDate)
        // restore the item

How to edit field labels for user friendliness with a custom Template Builder

This article was previously posted as How to edit field labels for user friendliness on June 3rd, 2013

Working with Sitecore as a developer is all about servicing the content editor. Content editors need to deliver great content, and as developers we can provide them with solutions that help them do this. Nevertheless, there can be some friction in how information such as content fields are structured by developers and the way this is best presented to content editors. How can we serve both needs easily? Enter the Redhotminute Template Builder.

What the ‘friction’ is about

One of the things that is crucial to a content editor is the label above the field they have to fill in Sitecore. This label should tell them what information should go into the field. At the same time, the developer – if he’s like me – wants to make sure a field name is unique and the name indicates where to find the field within Sitecore.

I do this by prefixing the field names with an abbreviation of the template name. In my case this can result in tittle field names such as ‘doc_page_title’. By default the name of a field is used as the label for the field. This is a nice title to a developer, but it’s gibberish to a content editor.

Displaying the right information

So how can we make sure field labels are optimized in such a way they serve the needs of both the developer as well as the content editor? As described in Oasis’s Mark Ursino’s blog post about Sitecore Item and Field names it is easy to change the field label to display a name other than the field name. The label displays the field name by default, but if we fill the title field then this value is used as the label. This is standard functionality in Sitecore and can be set in the field item itself.

Display the right information

Another feature described in Mark’s post is the use of the Short Description text. This makes it possible to provide the content editor with extra information about the field, for example an image field with the extra information ‘the recommended image dimensions are 120×80 px, PNG’. This field is also set in the field item, but then by changing ribbons and opening dialogs.

Go to the help dialog

Enter a short description

Template Builder to the rescue

Velir’s Tim Braga describes in a post about his Enhanced Template Builder how he added a required checkbox for each field in the template builder. This avoids having to drill down for each field to set the validation options to make the field required. His solution makes it possible to make a field required from the template builder itself. This inspired me to have a look at the template builder myself.

The title field and the short description of a field item enable us to provide the content editor with useful information and have a nice ‘technical’ field name for us developers to work with. But if you have to do this for a template with ten fields, it’s quite a bit of ‘clicking around’. So how can we do this more efficiently? The Redhotminute Template Builder offers the solution.

Smoothing the friction

I have added two columns to the field definitions: Title and Short Description. This allows me to fill in all necessary fields from the template builder. At one glance, I can see and edit all the Titles and Short Descriptions used in a template.

Enter the title and Short description in the template builder

This makes it possible for me to use technical field names. As a developer, I like to use such names for structuring information. At the same time, I can set a label name a content editor understands and provide him or her with extra information such as image requirements if necessary.

See the result in your template

This solutions makes it easy for us developers to use the structured data we want while at the same time displaying information that makes perfect sense to the content editor. This way, we can smooth the friction and effortlessly use the template builder to do what our job is all about in Sitecore: enabling content editors to deliver great content.

The source can be found at Github

The module can be downloaded in the Sitecore Marketplace