From 7ee0a278f73d5eb90282c8ba5243d287d86622dc Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 24 Apr 2017 14:57:57 +0100 Subject: [PATCH] Adss null check --- src/Umbraco.Web/Editors/TemplateController.cs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Web/Editors/TemplateController.cs b/src/Umbraco.Web/Editors/TemplateController.cs index 0f00170000..78855c95c2 100644 --- a/src/Umbraco.Web/Editors/TemplateController.cs +++ b/src/Umbraco.Web/Editors/TemplateController.cs @@ -135,21 +135,26 @@ namespace Umbraco.Web.Editors var templateHasChildren = Services.FileService.GetTemplateDescendants(display.Id); foreach (var childTemplate in templateHasChildren) - { + { //template ID to find - var templateIDInPath = "," + display.Id + ","; - + var templateIdInPath = "," + display.Id + ","; + + if (string.IsNullOrEmpty(childTemplate.Path)) + { + continue; + } + //Find position in current comma seperate string path (so we get the correct children path) - var positionInPath = childTemplate.Path.IndexOf(templateIDInPath) + templateIDInPath.Length; - + var positionInPath = childTemplate.Path.IndexOf(templateIdInPath) + templateIdInPath.Length; + //Get the substring of the child & any children (descendants it may have too) - var childTemplatePath = childTemplate.Path.Substring(positionInPath); - - //As we are updating the template to be a child of a master + var childTemplatePath = childTemplate.Path.Substring(positionInPath); + + //As we are updating the template to be a child of a master //Set the path to the master's path + its current template id + the current child path substring - childTemplate.Path = master.Path + "," + display.Id + "," + childTemplatePath; - - //Save the children with the updated path + childTemplate.Path = master.Path + "," + display.Id + "," + childTemplatePath; + + //Save the children with the updated path Services.FileService.SaveTemplate(childTemplate); } }