diff --git a/src/Umbraco.Core/Services/IFileService.cs b/src/Umbraco.Core/Services/IFileService.cs index d32c984b5e..8596424b03 100644 --- a/src/Umbraco.Core/Services/IFileService.cs +++ b/src/Umbraco.Core/Services/IFileService.cs @@ -200,7 +200,7 @@ namespace Umbraco.Core.Services /// Attempt> CreateTemplateForContentType(string contentTypeAlias, string contentTypeName, int userId = 0); - ITemplate CreateTemplateWithIdentity(string name, string content, ITemplate masterTemplate = null, int userId = 0); + ITemplate CreateTemplateWithIdentity(string name, string alias, string content, ITemplate masterTemplate = null, int userId = 0); /// /// Deletes a template by its alias diff --git a/src/Umbraco.Core/Services/Implement/FileService.cs b/src/Umbraco.Core/Services/Implement/FileService.cs index cbf961595e..d85b0ca1ba 100644 --- a/src/Umbraco.Core/Services/Implement/FileService.cs +++ b/src/Umbraco.Core/Services/Implement/FileService.cs @@ -390,16 +390,17 @@ namespace Umbraco.Core.Services.Implement /// Create a new template, setting the content if a view exists in the filesystem /// /// + /// /// /// /// /// - public ITemplate CreateTemplateWithIdentity(string name, string content, ITemplate masterTemplate = null, int userId = 0) + public ITemplate CreateTemplateWithIdentity(string name, string alias, string content, ITemplate masterTemplate = null, int userId = 0) { // file might already be on disk, if so grab the content to avoid overwriting - var template = new Template(name, name) + var template = new Template(name, alias) { - Content = GetViewContent(name) ?? content + Content = GetViewContent(alias) ?? content }; if (masterTemplate != null) diff --git a/src/Umbraco.Tests/Services/FileServiceTests.cs b/src/Umbraco.Tests/Services/FileServiceTests.cs index b419ae186f..fa27a3ee81 100644 --- a/src/Umbraco.Tests/Services/FileServiceTests.cs +++ b/src/Umbraco.Tests/Services/FileServiceTests.cs @@ -19,8 +19,8 @@ namespace Umbraco.Tests.Services [Test] public void Create_Template_Then_Assign_Child() { - var child = ServiceContext.FileService.CreateTemplateWithIdentity("child", "test"); - var parent = ServiceContext.FileService.CreateTemplateWithIdentity("parent", "test"); + var child = ServiceContext.FileService.CreateTemplateWithIdentity("Child", "child", "test"); + var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); child.SetMasterTemplate(parent); ServiceContext.FileService.SaveTemplate(child); @@ -34,8 +34,8 @@ namespace Umbraco.Tests.Services [Test] public void Create_Template_With_Child_Then_Unassign() { - var parent = ServiceContext.FileService.CreateTemplateWithIdentity("parent", "test"); - var child = ServiceContext.FileService.CreateTemplateWithIdentity("child", "test", parent); + var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); + var child = ServiceContext.FileService.CreateTemplateWithIdentity("Child", "child", "test", parent); child.SetMasterTemplate(null); ServiceContext.FileService.SaveTemplate(child); @@ -48,9 +48,9 @@ namespace Umbraco.Tests.Services [Test] public void Can_Query_Template_Children() { - var parent = ServiceContext.FileService.CreateTemplateWithIdentity("parent", "test"); - var child1 = ServiceContext.FileService.CreateTemplateWithIdentity("child1", "test", parent); - var child2 = ServiceContext.FileService.CreateTemplateWithIdentity("child2", "test", parent); + var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); + var child1 = ServiceContext.FileService.CreateTemplateWithIdentity("Child1", "child1", "test", parent); + var child2 = ServiceContext.FileService.CreateTemplateWithIdentity("Child2", "child2", "test", parent); var children = ServiceContext.FileService.GetTemplates(parent.Id).Select(x => x.Id).ToArray(); @@ -58,5 +58,18 @@ namespace Umbraco.Tests.Services Assert.IsTrue(children.Contains(child2.Id)); } + [Test] + public void Create_Template_With_Custom_Alias() + { + var template = ServiceContext.FileService.CreateTemplateWithIdentity("Test template", "customTemplateAlias", "test"); + + ServiceContext.FileService.SaveTemplate(template); + + template = ServiceContext.FileService.GetTemplate(template.Id); + + Assert.AreEqual("Test template", template.Name); + Assert.AreEqual("customTemplateAlias", template.Alias); + } + } } diff --git a/src/Umbraco.Web/Editors/TemplateController.cs b/src/Umbraco.Web/Editors/TemplateController.cs index ac9341a095..f91d27ceae 100644 --- a/src/Umbraco.Web/Editors/TemplateController.cs +++ b/src/Umbraco.Web/Editors/TemplateController.cs @@ -184,7 +184,7 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.NotFound); } - var template = Services.FileService.CreateTemplateWithIdentity(display.Alias, display.Content, master); + var template = Services.FileService.CreateTemplateWithIdentity(display.Name, display.Alias, display.Content, master); Mapper.Map(template, display); }