More in this section

Forums / Developing with Sitefinity / Reassign page templates programatically

Reassign page templates programatically

2 posts, 0 answered
  1. Laura
    Laura avatar
    311 posts
    25 Feb 2008
    20 Jul 2010
    Link to this post
    I think this was already posted in the forums however I can not seem to find it again.

    Is there a way to re-assign a template to a page programatically?  I have a big section of the web site with about 200 pages that need a new template. Instead of editing each individual page directly I thought I saw some code posted to run a script in the database to updated it automatially??

    Thank you.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    20 Jul 2010
    Link to this post
    Hello Laura,

    Here is a sample that you can use to change the template of a page

    var cmsManager = new CmsManager();
    // first you need to get all pages cmsManager.GetPages() and then loop
    // through each page
    var page = cmsManager.GetPage(cmsPage.ID, true);
    IPageTemplate SavepageTemplate = cmsManager.GetTemplate("Default");
    page.Staged.SetTemplate(pageTemplate.ID, string.Empty);

    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered