More in this section
Forums / Developing with Sitefinity / Applying Template to Multiple Pages/Whole Site

Applying Template to Multiple Pages/Whole Site

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Sam
    Sam avatar
    1 posts
    21 Jan 2008
    07 Oct 2008
    Link to this post
    Does anyone know if there a way to apply a different template and/or theme to an entire site, without editing each page to change the template?

  2. Pepi
    Pepi avatar
    981 posts
    31 Jan 2017
    09 Oct 2008
    Link to this post
    Hi Sam,

    I would suggest you use Pages API and set the page themes/templates programatically. Here is a simple example:

               CmsManager manager = new CmsManager(); 
            IList pages = manager.GetPages(); 
            for (int i = 0; i < pages.Count; i++) 
                // Gets the current page    
                ICmsPage currentPage = (ICmsPage)pages[i]; 
                if (currentPage.PageType == CmsPageType.Normal) 
                    // Gets the Staged version of the page 
                    ICmsPage page = (ICmsPage)manager.GetPage(currentPage.ID, true); 
                    // Checks-out the Staged version of the page    
                    IStagedPage staged = page.Staged.CheckOut(); 
                    // Gets the template with a name "default" and sets it for the page   
                    IPageTemplate template = manager.GetTemplate("default"); 
                    staged.SetTemplate(template.ID, "Orange with left sidebar");  
                    // Gets the staged page for a specific version and checks-in   
                    staged = manager.GetPage(page.ID, true).GetVersion(staged.Version); 
                    // Publishes the page    
                    page = (ICmsPage)manager.GetPage(page.ID, true); 

    Do let us know if you need any further assistance.

    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered