Kentico CMS 7.0 Developer's Guide

Page templates and sites

Page templates and sites

Previous topic Next topic Mail us feedback on this topic!  

Page templates and sites

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

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example assigns a page template to a site.

 

private bool 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);
 
        return true;
    }
 
    return false;
}

 

The following example removes a page template from a site.

 

private bool 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);
 
        return true;
    }
 
    return false;
}