Sitecore: Should I Modify A Built-In Template?

Rainfall Software
Rainfall Software
Published in
2 min readJan 17, 2023

No…. Thanks for reading.

Ok, we need a bit more detail than that. Sometime a scenario comes along when we need to add additional functionality to one of the pre-existing Sitecore templates. The obvious action in this situation is to add the necessary fields and configuration to the template in question and proceed building our feature. This will work in the short-term, but will cause all sorts of problems down the road, especially when you’re looking to upgrade to a later version of Sitecore.

Photo by Tim Mossholder on Unsplash

Rather than modifying the existing Sitecore template, it’s a better practice to create a template of your own that extends the built-in template. In the Content tab of your new template, you can add the Sitecore template that you want to extend to the Base Template field. This will inherit all the fields from this template without effecting the original. You can then add the additional fields you need.

In a recent project, I was tasked to add some additional functionality to Sitecore media items. Rather than modify the built-in File template under the System folder, I created a new template called CustomFile, which inherited from the Sitecore original.

Once this was done, I needed to convert a bunch of existing items over to my new template. To do this, I created a quick Powershell script that would convert the items from the Sitecore template to my custom one. Since my template inherits from the original, none of the data in the existing fields will be lost.

The script looks something like:

$fileItems = Get-Item -Path "master:" -Query "fast:/sitecore/media library/Project/MyProject//*[@@templateid='{962B53C4-F93B-4DF9-9821-415C867B8903}'"
ForEach ($file in $fileItems) {
Set-ItemTemplate -Path $file.ItemPath -Template "/sitecore/templates/Foundation/MyFoundation/CustomFile"
}

To make sure that any new items follow the same pattern, I can also adjust the insert options for the media library folder in question to make sure that content editors create new CustomFile items, rather than using the standard template.

--

--