Posts

Showing posts with the label Branch template

Optimizing Sitecore Branch Templates for Seamless Page Creation Without Datasource Path Modification

Hello everyone, in this blog, I’ll address a common challenge I’ve faced when using branch templates to create item structures. I noticed that when creating a branch structure and assigning a local datasource item, the datasource does not update automatically during item creation—the local datasource continues to reference the branch’s local items. In this blog, we’ll explore how to use a Sitecore pipeline to automatically update the datasource path. This solution will work with all version of Sitecore even if it is XMC, Headless or XP. I have tried this on XMC and it works absolutely fine Let's jump to solution. We will override AddFromTemplateProcessor and extend it to add our logic. Let's create AddFromBranchPresetProcessor which extends AddFromTemplateProcessor . Check below code. using Sitecore; using Sitecore.Data.Fields; using Sitecore.Data.Items; using Sitecore.Diagnostics; using Sitecore.Layouts; using Sitecore.Pipelines.ItemProvider.AddFromTemplate; us...