Category Archives: User Experience

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 (http://www.sitecore.net/sv-se/learn/blogs/best-practice-blogs/jan-hebnes/posts/2012/09/unsharing-the-layout-field-in-sitecore.aspx).
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 (https://gist.github.com/janhebnes/3550920) 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: https://github.com/martywoods/Sc.Modules.Events.LayoutDataSourceReferenceUpdater
Available on NuGet: http://www.nuget.org/packages/Sc.Modules.Events.LayoutDataSourceReferenceUpdater/

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 sitecore.net 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