Adding Sections

Adding Sections


  • Each section appears as a collapsible group of fields in the Content Editor
  • Use sections to group fields logically, making them easier for content authors to find and use
  • Consider creating data templates with a single section and related fields to use as one of multiple base templates. This makes it easy to build up a new data template with multiple standard sections of fields.
  • Do not refer to sections when accessing items from code

Naming Templates, Field Sections and Fields

  • Use simple, relevant, and easy to understand names
  • Sitecore displays names to technical and non-technical users by default
  • Choose names that business users and content authors will understand
  • Avoid using a naming convention that recommends prefixes or suffixes

Steps to Create a Template

  1. Create an object for the database where the item is located - typically “master”
  2. Create item based on a specific template. We use ‘Document’ template as example.
    CreateTemplate method in this snippet requires template name and an Item as parameters.
  3. Use a security disabler to allow changes and place in a using block to ensure cleanup occurs
  4. Use the CreateTemplate method to create a new template and assign it to a template object
    Add a section “MySection”
  5. Add a field and change its attributes
  6. Open the edit state for the item
  7. Set the attributes for the single template field
  8. Close the edit state for the item
  9. Use an EditContext block to set the shared attribute

C# Web Control Code

Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item base = db.Templates["basetemplatepath"].InnerItem.Parent;
using (new Sitecore.SecurityModel.SecurityDisabler())
      Sitecore.Data.Items.TemplateItem template = db.Templates.CreateTemplate("templatename", base);
      TemplateSectionItem section = template.AddSection("sectionname");
      TemplateFieldItem field = section.AddField("fieldname");