The following example assigns a page template to a site.
privatebool AddPageTemplateToSite() {
// Get the page template PageTemplateInfo template = PageTemplateInfoProvider.GetPageTemplateInfo("MyNewTemplate");
if (template != null) { int templateId = template.PageTemplateId; int siteId = CMSContext.CurrentSiteID; // Save the binding PageTemplateSiteInfoProvider.AddPageTemplateToSite(templateId, siteId); returntrue; } returnfalse; }
The following example removes a page template from a site.
privatebool RemovePageTemplateFromSite() {
// Get the page template PageTemplateInfo removeTemplate = PageTemplateInfoProvider.GetPageTemplateInfo("MyNewTemplate");
if (removeTemplate != null) { int siteId = CMSContext.CurrentSiteID;
// Get the binding PageTemplateSiteInfo templateSite = PageTemplateSiteInfoProvider.GetPageTemplateSiteInfo(removeTemplate.PageTemplateId, siteId);
// Delete the binding PageTemplateSiteInfoProvider.DeletePageTemplateSiteInfo(templateSite); returntrue; } returnfalse; }