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); } |