Copy one template to other or creating duplicate templates.
Hi,
We can create the duplicate pages but there is no feature to duplicate or create the copy of the templates. I tried doing it programmatically in 2 ways but it didn't helped. Here is the code below.
1. Creating a new template with the same master page as the old template.
string masterFilePath = " ~/App_Data/Sitefinity/WebsiteTemplates/MyTemplate/App_Master/";
PageTemplate template = null;
var pageManager = PageManager.GetManager();
var templates = pageManager.GetTemplates().Where(x => x.Title == txtName.Text.Trim()).FirstOrDefault();
template = pageManager.CreateTemplate();
template.Name = txtNewTempName.Text.Trim();
template.Title = txtNewTempName.Text.Trim();
template.MasterPage = masterFilePath;
pageManager.SaveChanges();
PageTemplate template = null;
var pageManager = PageManager.GetManager();
var templates = pageManager.GetTemplates().Where(x => x.Title == txtName.Text.Trim()).FirstOrDefault();
template = pageManager.CreateTemplate();
Guid id = new Guid();
id = template.Id;
template = templates;
template.Id = id;// Showing Error here
template.Name = txtNewTempName.Text.Trim();
template.Title = txtNewTempName.Text.Trim();
template.MasterPage = masterFilePath;
pageManager.SaveChanges();
Funny, I thought it was possible to create a new template and choose to base it on an existing one. That way, you get a new template that looks exactly like another one that you already have. I am sure its possible. Can you double-check?
Andrei
Hi Andrei,
Yes, we can create it using base template but the in that case any changes made in the base template will be reflected in the new template. I don't want that to happen. I want the new template to be independent of the old template but looks similar.
Thanks,
Gagan
Ok, I see what you mean. I am not aware of any way to break the inheritance once you have created the new template. I will have a look around, but this is a good thing to suggest in the Suggestions forum. Sorry I couldn't help. Andrei