Sitefinity CMS

Creating Templates Send comments on this topic.
See Also
Developing with Sitefinity > Pages > Pages API Walkthrough > Templates > Creating Templates

Glossary Item Box

This topic explains how to use Sitefinity Pages API to programmatically create new templates.

 

Create a new template with specified name and assign it a master page file:

CreateTemplate(string name) Copy Code
// create a new instance of CmsManager
Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
// create a new template with specified name
Telerik.Cms.IPageTemplate newTemplate = cmsManager.CreateTemplate("New template");
// before we save the template, let's assign it a master page file
// master page file HAS TO BE located in root/App_Master folder
newTemplate.MasterPage = "Default.master";
// finally, let's save the template with CmsManager
cmsManager.SaveTemplate(newTemplate);

 

Create a new template by duplicating existing template and then change the theme:

DuplicateTemplate(IPageTemplate template) Copy Code
// create a new instance of CmsManager
Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
// let's get all templates and make the duplicate from the first one in the list
IList allTemplates = cmsManager.GetTemplates();
// create a new template by duplicating the first in the list of all templates
Telerik.Cms.IPageTemplate customTemplate = cmsManager.DuplicateTemplate((Telerik.Cms.IPageTemplate)allTemplates[0]);
// before we save our new template, let's change its theme
// the themes are located in App_Themes folder
customTemplate.Theme = "Blue with right sidebar";
// finally, we are going to save the template with CmsManager
cmsManager.SaveTemplate(customTemplate);

 

See Also