In this topic we are going to show how to find one or more templates inside of Sitefinity.
There are several methods to find templates:
Find all templates:
| GetTemplates() |
Copy Code |
|
// create a new instance of CmsManager Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager(); // get all templates IList
allTemplates = cmsManager.GetTemplates(); // for each template write out its name and number of pages using
it foreach(Telerik.Cms.IPageTemplate template in allTemplates)
Response.Write(template.Name + " - used by " + template.Pages.Count + " pages.");
|
Find a specific template by its ID:
| GetTemplate(Guid id) |
Copy Code |
|
// create a new instance of CmsManager Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager(); // for demonstration purpose we are first going to obtain
an id of a first
// template and then we are going to retrieve a template by using that id
// get all templates IList allTemplates = cmsManager.GetTemplates();
Telerik.Cms.IPageTemplate firstTemplate = (Telerik.Cms.IPageTemplate)allTemplates[0];
Guid firstTemplateId = firstTemplate.ID; // get template by id Telerik.Cms.IPageTemplate template =
cmsManager.GetTemplate(firstTemplateId); // write out the name of master page used by template Response.Write(template.MasterPage);
|
Find a specific template by its ID and pass additional argument to specify whether you want to edit the template or not:
| GetTemplate(Guid id, bool forEdit) |
Copy Code |
|
// create a new instance of CmsManager Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager(); // for demonstration purpose we are first going to obtain
an id of a first
// template and then we are going to retrieve a template by using that id
// get all templates IList allTemplates = cmsManager.GetTemplates();
Telerik.Cms.IPageTemplate firstTemplate = (Telerik.Cms.IPageTemplate)allTemplates[0];
Guid firstTemplateId = firstTemplate.ID; // get template by id and specify the second, "forEdit" argument, to false since
we do not want
// to edit the template Telerik.Cms.IPageTemplate template =
cmsManager.GetTemplate(firstTemplateId, false); // write out the name of default theme used by
template Response.Write(template.Theme);
|
Find a template by its name:
| GetTemplate(string name) |
Copy Code |
|
// create a new instance of CmsManager Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager(); // let's find the template with name
"Default" Telerik.Cms.IPageTemplate defaultTemplate = cmsManager.GetTemplate("Default"); // if template exists, write out how many pages uses
it if (defaultTemplate != null)
Response.Write(defaultTemplate.Pages.Count.ToString()); else
Response.Write("Template with such name could not be found!");
|
See Also