|
API examples for newer versions
Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.
|
The following example creates a page template scope and assigns it to a template.
private bool CreatePageTemplateScope()
{
// Get template object
PageTemplateInfo template = PageTemplateInfoProvider.GetPageTemplateInfo("MyNewTemplate");
// If template exists
if (template != null)
{
// Page template isn't available for all pages
template.PageTemplateForAllPages = false;
// Create new template scope
PageTemplateScopeInfo newScope = new PageTemplateScopeInfo();
// Set some properties
newScope.PageTemplateScopeTemplateID = template.PageTemplateId;
newScope.PageTemplateScopeSiteID = CMSContext.CurrentSiteID;
newScope.PageTemplateScopePath = "/";
newScope.PageTemplateScopeLevels = "/{0}/{1}";
// Save scope to database
PageTemplateScopeInfoProvider.SetPageTemplateScopeInfo(newScope);
// Update page template
PageTemplateInfoProvider.SetPageTemplateInfo(template);
return true;
}
return false;
}
|
The following example removes a page template scope from a template and deletes it.
private bool DeletePageTemplateScope()
{
string columns = "";
string where = "";
// Get template object
PageTemplateInfo template = PageTemplateInfoProvider.GetPageTemplateInfo("MyNewTemplate");
// If template exists
if (template != null)
{
where = "PageTemplateScopeTemplateID = " + template.PageTemplateId;
}
DataSet scopes = PageTemplateScopeInfoProvider.GetTemplateScopes(columns, where, null, 0);
if (!DataHelper.DataSourceIsEmpty(scopes))
{
// Get the page template scope
PageTemplateScopeInfo deleteScope = new PageTemplateScopeInfo(scopes.Tables[0].Rows[0]);
// Delete the page template scope
PageTemplateScopeInfoProvider.DeletePageTemplateScopeInfo(deleteScope);
return true;
}
return false;
}
|