More in this section

Forums / Developing with Sitefinity / Copy one template to other or creating duplicate templates.

Copy one template to other or creating duplicate templates.

4 posts, 0 answered
  1. Gagandeep
    Gagandeep avatar
    8 posts
    Registered:
    29 Nov 2011
    27 Feb 2012
    Link to this post
    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
  2. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    27 Feb 2012
    Link to this post
    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
  3. Gagandeep
    Gagandeep avatar
    8 posts
    Registered:
    29 Nov 2011
    27 Feb 2012
    Link to this post
    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
  4. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    28 Feb 2012
    Link to this post
    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
4 posts, 0 answered