Skip to main content

Introduction:

In the world of content management, Sitecore reigns as a popular choice due to its flexibility and extensibility. However, managing complex content templates, especially those with multiple sections and template inheritance in a Helix architecture, can sometimes lead to chaos in the Content Editor.

When your content tree sprawls across a multitude of templates, you want to ensure a logical and user-friendly experience for your content editors. In a lot of posts (stack-exchange, blogpost) people tend to configure then just different sort orders on sections on base templates, but then if those base-templates end up being constructed of more base templates that use the same section name, you quickly end up in constantly re-doing/re-setting the sort order of those sections, not something you would want. What if on certain Page templates you want a different sort order?

In this blog post, I’ll ‘hopefully ;-)’ explore the ultimate solution to section sorting with template inheritance in the Sitecore Content Editor, a feature that can dramatically enhance your content management experience.

Understanding the Challenge:

Sitecore’s flexible architecture allows content templates to inherit from base templates. However, this flexibility can lead to sections being displayed in seemingly random orders in the Content Editor. This can be especially challenging when adhering to the Helix principles, where template inheritance is a common practice. Add base SXA templates into the mix (which often time you have no control over, since you don’t want to store these items under source control) and it’s almost not doable to control the sort order of all your sections. To ensure a streamlined content creation process and a user-friendly interface, we need a solution that addresses this issue.

Overview of the Solution:

The solution to the section sorting challenge lies in creating a custom processor within Sitecore. This processor will seamlessly integrate with the ‘getContentEditorFields’ pipeline, allowing for dynamic sorting of sections based on the current template. Here’s a quick overview of the solution:

  • Custom Processor: We’ll craft a custom processor that aligns with Sitecore’s pipeline architecture, ensuring smooth integration.
  • Configuration: To define the order of sections for different templates, we’ll add this through configuration. A custom config file will house the section sorting orders for each template.
  • Dynamic Sorting: Our custom processor will fetch the current template being edited and sort the sections based on the defined order. This ensures that content editors encounter a consistent and logical section order, irrespective of the template’s inheritance.

SectionsSortingOverride processor:

To implement the custom processor, you’ll need to add the following code to your Sitecore solution:

The Configuration Patch:

To add the processor to the ‘getContentEditorFields’ pipeline, you’ll need to create a patch configuration file like this:

Configuring Section Sorting:

Configuring section sorting is straightforward with a Sitecore patch config file at the Project level file. This file allows you to specify the order of sections for each Project template. Here’s a snippet of how the configuration might look:

And this is in the result of how for example the ‘Home’  item would look like in terms of sections (even inheriting from some base SXA templates, such as ‘_Seo Metadata’, ‘_Opengraph Metadata’, etc…).

Ultimate Sitecore Section Sorting with Template Inheritance Content Editor result

Section sorting in the Sitecore Content Editor is a game-changer for efficient content management. It provides content editors with a logical and consistent order of sections, regardless of template inheritance in a Helix architecture. By creating a custom processor and configuring the desired sorting order, you can enhance the usability and efficiency of the Content Editor interface.

Happy Sitecore-ing!

–Robbert