Page templates


List of examples:

Page template categories

Creating a page template category



// Creates a new page template category object
PageTemplateCategoryInfo newCategory = new PageTemplateCategoryInfo();

// Sets the category properties
newCategory.DisplayName = "New category";
newCategory.CategoryName = "NewCategory";             

// Saves the page template category to the database
PageTemplateCategoryInfoProvider.SetPageTemplateCategoryInfo(newCategory);

> Back to list of examples

Updating a page template category



// Gets the page template category
PageTemplateCategoryInfo updateCategory = PageTemplateCategoryInfoProvider.GetPageTemplateCategoryInfo("NewCategory");
if (updateCategory != null)
{
    // Updates the category properties
    updateCategory.DisplayName = updateCategory.DisplayName.ToLower();

    // Saves the changes to the database
    PageTemplateCategoryInfoProvider.SetPageTemplateCategoryInfo(updateCategory);
}

> Back to list of examples

Updating multiple page template categories



// Gets all page template categories from the first level of the tree
var categories = PageTemplateCategoryInfoProvider.GetPageTemplateCategories().WhereEquals("CategoryLevel", 1);

// Loops through the page template categories
foreach (PageTemplateCategoryInfo category in categories)
{
    // Updates the category properties
    category.DisplayName = category.DisplayName.ToUpper();

    // Saves the changes to the database
    PageTemplateCategoryInfoProvider.SetPageTemplateCategoryInfo(category);
}

> Back to list of examples

Deleting a page template category



// Gets the page template category
PageTemplateCategoryInfo deleteCategory = PageTemplateCategoryInfoProvider.GetPageTemplateCategoryInfo("NewCategory");

if (deleteCategory != null)
{
    // Deletes the page template category
    PageTemplateCategoryInfoProvider.DeletePageTemplateCategory(deleteCategory);
}

> Back to list of examples

Page templates

Creating a page template



// Gets a parent category for the new page template
PageTemplateCategoryInfo category = PageTemplateCategoryInfoProvider.GetPageTemplateCategoryInfo("NewCategory");
if (category != null)
{
    // Creates a new page template object
    PageTemplateInfo newTemplate = new PageTemplateInfo();

    // Sets the page template properties
    newTemplate.DisplayName = "New template";
    newTemplate.CodeName = "NewTemplate";
    newTemplate.Description = "This is a page template description.";
    newTemplate.CategoryID = category.CategoryId;
    newTemplate.PageTemplateType = PageTemplateTypeEnum.UI;

    // Saves the page template to the database
    PageTemplateInfoProvider.SetPageTemplateInfo(newTemplate);
}

> Back to list of examples

Updating a page template



// Gets the page template
PageTemplateInfo updateTemplate = PageTemplateInfoProvider.GetPageTemplateInfo("NewTemplate");
if (updateTemplate != null)
{
    // Updates the page template properties
    updateTemplate.DisplayName = updateTemplate.DisplayName.ToLower();

    // Saves the changes
    PageTemplateInfoProvider.SetPageTemplateInfo(updateTemplate);
}

> Back to list of examples

Updating multiple page templates



// Gets all page templates assigned to the current site whose code name starts with 'NewTemplate'
var templates = PageTemplateInfoProvider.GetTemplates()
                                            .WhereStartsWith("PageTemplateCodeName", "NewTemplate")
                                            .OnSite(SiteContext.CurrentSiteID);

// Loops through individual page templates
foreach (PageTemplateInfo template in templates)
{                   
    // Updates the template properties
    template.DisplayName = template.DisplayName.ToUpper();

    // Saves the changes to the database
    PageTemplateInfoProvider.SetPageTemplateInfo(template);
}

> Back to list of examples

Deleting a page template



// Gets the page template
PageTemplateInfo deleteTemplate = PageTemplateInfoProvider.GetPageTemplateInfo("NewTemplate");

if (deleteTemplate != null)
{
    // Deletes the page template
    PageTemplateInfoProvider.DeletePageTemplate(deleteTemplate);
}

> Back to list of examples