Copy one template to other or creating duplicate templates.

Posted by Community Admin on 04-Aug-2018 17:55

Copy one template to other or creating duplicate templates.

All Replies

Posted by Community Admin on 27-Feb-2012 00:00
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();


2. Creating a blank template and coping everything from the old template except the id.
Here is the code for that.
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();

Any help for creating the duplicate of the templates will be appreciated.

Thanks,
Gagan
Posted by Community Admin on 27-Feb-2012 00:00
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
Posted by Community Admin on 27-Feb-2012 00:00
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
Posted by Community Admin on 28-Feb-2012 00:00
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
This thread is closed