Managing page template scopes

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can create a new page template scope and assign it to a template:

 

[C#]

 

using CMS.PortalEngine;

using CMS.CMSHelper;

 

...

     

        // Get template object

        PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo("TestPageTemplate");

 

        // If template exists

        if (pti != null)

        {

            // Set page template so that it isn't available for all pages

            pti.PageTemplateForAllPages = false;

 

            // Create new template scope

            PageTemplateScopeInfo ptsi = new PageTemplateScopeInfo();

 

            // Set scope properties

            ptsi.PageTemplateScopeTemplateID = pti.PageTemplateId;

            ptsi.PageTemplateScopeSiteID = CMSContext.CurrentSiteID;

            ptsi.PageTemplateScopePath = "/Home";

            ptsi.PageTemplateScopeLevels = "/{0}/{1}";

 

            // Save scope to database

            PageTemplateScopeInfoProvider.SetPageTemplateScopeInfo(ptsi);

 

            // Update page template

            PageTemplateInfoProvider.SetPageTemplateInfo(pti);

 

        }

 

The following sample code shows how you can delete a page template scope from the system:

 

[C#]

 

using CMS.PortalEngine;

 

...

 

        // Get template scope by ID

        PageTemplateScopeInfo ptsi = PageTemplateScopeInfoProvider.GetPageTemplateScopeInfo(1);

 

        // If exists

        if (ptsi != null)

        {

            // Delete from database

            PageTemplateScopeInfoProvider.DeletePageTemplateScopeInfo(ptsi);

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_portal_engine_managing_page_template_scopes.htm