Tag Archives: sorting

Sorting Template Sections in Sitecore

Here is a little nugget for those Sitecore enthusiasts who want the ability to sort the sections in a content item.  For years I didn’t know about this as a Sitecore Developer so if this helps just one person I have done my job to pass on this helpful knowledge.  Kudos to the guys at Active Commerce for showing me when I went through Active Commerce Certification training.  Active Commerce is a fantastic add-on to Sitecore for E-Commerce functionality and I highly recommend for businesses with lots of products that need an online storefront.  You can find out more about Active Commerce at their website http://www.activecommerce.com.

So let’s just say you have a Content Page template that has the following sections:

  • Page Data
  • Meta Data

I would like the Page Data section to come before the Meta Data section when the template is used to create a new item.  Below is what my template structure looks like:

Template Structure

Template Structure

The Content Page has the PageBase template selected as the Base Template.  The PageBase template has the _pageBase and _metaBase templates selected as the Base Templates.  Both _pageBase and _metaBase templates have the Standard template selected as the Base Template.

The following template sections are selected in this order on the PageBase template __Base template TreeView:

  • _pageBase
  • _metaBase

Being that they are selected in this order you would think that they should show up in the Content item sorted in this manner since the TreeView allows you to sort them.  However, below is what the __Standard Values for the Content Page displays:

Template Sections Order

Template Sections Order

Here is the solution to get the template sections in the order you wish.  In order to sort the sections you must set the Sortorder in the the Template Sections items.  In this case, there are 2 sections; Page Data and Meta Data as seen below:

Template Section

Template Section

The section sorting order is sorted alphabetically unless the sortorder is specifically stated using the Sortorder field in the Template Section items.  Hence, the reason Meta Data comes before Page Data (refer to Template Sections Order).  By default, the Sortorder field is set to 100 as seen below:

Sortorder Field

Sortorder Field

Depending on how many sections you want to sort you can increment these numbers to achieve the desired result.  For example, if I had 4 sections I would just add 100 to the other Sortorder fields in the respective Template Section items.  Since I have 2 sections I only need to set the other Meta Data Sortorder field to 200 and it will place that section underneath the Page Data section as seen below:

Section Sorting Order Achieved

Section Sorting Order Achieved

This knowledge can be used to help out the organization of your templates and give power to Content Editors to access the most relevant sections of items first when there are many sections in the an item.  Happy coding!

Fast and easy sorting in Sitecore

You can easily sort items in the content tree by clicking on the Alt button and then dragging the item where you want it and then letting go.  You will then receive a dialog box that says, “Are you sure you want to move ‘XYZa’ item before ‘XYZb’ item?”  Just click the OK button the item will now be there.  For a quick sort this has saved me time and hopefully it will help you.  Happy coding!