+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Change template batch command

Change template batch command

4 posts, 1 answered
  1. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    30 Nov 2009
    Link to this post
    Hi Sitefinity people,
    Here's a scenario: I have applied a template to say 20 pages and then I accidentally delete said template.  When I upload the template again and give it the same name it is not applied to the above 20 pages.  Is there a way that I can apply the newly uploaded template to these 20 pages as a batch process?

    Thanks,
    Devin
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    01 Dec 2009
    Link to this post
    Hi Devin,

    Thank you for using our services.

    Unfortunately we do not have such functionality. However this can be easily achieved by code. You can use the pages API to get a page and change its template:
    // create a new instance of CmsManager
    Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
    // get the current node of sitemap
    Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
    // get the CmsPage represented by the current node and extract its ID
    Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
    Guid currentPageId = currentPage.ID;
    // for demonstration purposes we are going to retrieve the IPage object by passing the
    // id of the current object to the GetPage function. For the second argument ("forEdit")
    // we are going to pass true - which means we are able to modify this page
    Telerik.Cms.IPage pageFromDb = cmsManager.GetPage(currentPageId, true);
    // NOTE: to change the appearance and function of the page, we are going to use IStagedPage
    // object. IPage object contains Staged property of type IStagedPage, which will let us
    // to change the theme or add new control to the page for example.
    // first we are going to change the template of the page by getting a template with the manager
    pageFromDb.Staged.Template = cmsManager.GetTemplate(templateID);
    currentNode.CmsPage.Publish();
    // finally, because we are modifying the page we are currently viewing we need to refresh the page
    // to see the changes
    Response.Redirect(currentNode.Url);

    More information on the Pages API can be found here:Pages API Overview

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    01 Dec 2009
    Link to this post
    Hi Radoslav,
    Thanks a lot for the code!  This will be very helpful for me.  Are there plans to implement this functionality in future versions of Sitefinity?

    Thanks,
    Devin
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Dec 2009
    Link to this post
    Hello Devin,

    We have plans for group page operations for 4.0. For 3.x versions you have to use the API or create a backend tool that goes to each page you want to modify.

    Let us know if there is anything else that we can do for you.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 1 answered