Sitecore Environment-Specific Items: Introducing "Item Patching"
Environment-specific Sitecore values for items.
Start typing to search...
Sitecore’s configuration factory is one of its most useful Sitecore features, allowing developers to separate configurations into multiple files and easily manage environment-specific settings using rule-based configuration (env:define and env:require).
When it comes to Sitecore items, there is no built-in solution for environment-specific values. Ideally, no setting or environment-specific value should be stored as a Sitecore item, but in reality, this is not always feasible, legacy solutions, modules such as Coveo’s, and even Sitecore Experience Accelerator (SXA) use configuration items that are specific per environment.
I have worked on many projects where it was virtually impossible to request a database restore from one environment to another. My first attempt to solve this situation was creating PowerShell scripts to fix the data when they moved across environments, but it was never a sustainable solution.
To address this problem, I created this module that allows environment-specific values to be managed within Sitecore items in the content tree. It allows us to manage only the differences as child items, making it easy and clear that environment-specific values are present.
This module proved extremely useful for Sitecore XM and XP. One of the main reasons I have built it was to have the ability to restore databases from higher environments with no hassle, however as a positive side effect there are two other benefits, which also applies to XM Cloud - moving data with packages, and managing all environment values in a centralized location which also can be source controlled.
Managing Sitecore items across multiple environments presents challenges:
A module that enables developers to define environment-specific values within Sitecore items. The module will automatically apply changes based on predefined configurations, ensuring a seamless data restore experience.
.config file.You can make any item in the content tree to be subject of environment-specific values. In the image below, we have some fields from “Settings” differing across environments.
The module is available on GitHub: https://github.com/robertobarbedo/Sitecore.Feature.ItemPatching
ItemPatching.z.MyClient.config file.All project specific configuration can be done in App_Config/Include/ItemPatching.z.MyClient.config - there are pre-defined values to help understanding, they need to be replaced by your own project settings.
For Sitecore XM/XP you will need <add key="env:define" value="[dev,qa,etc]" /> in the web.config.
For XM Cloud you will need a project variable in your CM: $(env:ENVIRONMENT_NAME).
| ItemPatching.Environments | A list of all environments for your project. |
|---|---|
| ItemPatching.Environment | Note the difference is this setting is singular. It is used to match an ItemPatching Environment to an Actual Project Environment. |
| itemPatching > locations > location | These settings are used to scope the actions. You can define what template Item Patching will apply and in what parts of your content tree. |
| itemPatching > locations > location > path | Only descendants of path will be considered by the module. |
| itemPatching > locations > location > templates | Only items of the specified templates will have their environment-specific items created. |
Once configured and deployed to your solution, the module provides two new buttons under the Developer tab in the Sitecore Ribbon:

Additionally, changes can be applied in any other custom situation by code, using ItemPatchingManager.Apply().
Managing environment-specific Sitecore items has always been a challenge, the module proved itself valuable by making it easy to manage the differences between environments. By automating the Apply execution, it becomes a seamless experience.