Sitecore 5.0 API

TemplateItem Class

Represents a Template item.

For a list of all members of this type, see TemplateItem Members.

System.Object
   Sitecore.Data.Items.CustomItemBase
      Sitecore.Data.Items.TemplateItem

[Visual Basic]
Public Class TemplateItem
    Inherits CustomItemBase
[C#]
public class TemplateItem : CustomItemBase

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

A template defines the schema of an item. A schema describes which fields an item has and may contain default values for the fields, for instance a layout definition. Fields are grouped into sections that describe related fields. Templates supports inheritance.

The templates from which this template inherits are specified in the BaseTemplates property. All the fields and sections in a base template are also present in this template.

To retrieve the field definition items of the template, use the Fields collection property or the GetField method. Likewise the section items of the template can be retrieved using the GetSection and GetSections methods.

The AddTo methods adds a new item with this template to another item.

The template can be edited using the AddField, AddSection, RemoveField and RemoveSection. The template item does not have to be in editing mode as fields and section are seperate items. When a template is changed, the entire template cache is flushed and has be to rebuilt before items can be accessed again. This can be a performance costly operation and should be minimized.

The GetUsages method uses the search engine to retrieve items that are based on this template.

Example

This example creates a new item.

public Item AddItem(Item parent, string name) {
  Item result = null;

  TemplateItem template = Sitecore.Context.Database.Templates["Document"];
  
  if (template != null) {
    result = parent.Add(name, template);
  }

  return result;
}

Requirements

Namespace: Sitecore.Data.Items

Assembly: Sitecore.Kernel (in Sitecore.Kernel.dll)

See Also

TemplateItem Members | Sitecore.Data.Items Namespace