Skip to main content

Microsoft

Ignition Framework: Adding custom field definitions

One of the big drawing points of the Ignition Framework for Sitecore is its usage of field templates. In a traditional Sitecore environment, developers must explicitly add all fields to their templates directly. The Ignition approach is to define Sitecore fields as interfaces; simply inheriting an Ignition field’s interface will bring that field’s functionality into the working template. While Ignition provides many field definitions out-of-the-box, your solution might call for additional, custom fields.
You may be wondering why Ignition provides multiple fields of the same type. Ignition’s mechanism for template building requires all Ignition fields to have distinct names; you cannot inherit the same ignition field twice on the same template. So, for example, if your Ignition template calls for two distinct date fields, you will want to use DateField1 and DateField2.
This is a tutorial on how to create new field definitions for use in Ignition templates. In this example we will be creating a definition for a third DateField.

Step 1: Create a template for the field in Sitecore

  1. Create a new template in /sitecore/templates/Ignition/Fields/Content.
  2. Name the template DateField3.
  3. For the base template, select Templates/Ignition/ItemBase.
  4. Assign your new template an icon. (For this example we will use Business/32x32/calendar.png)
  5. On the template’s builder tab, create a section called Content and create the field DateField3 of type Datetime.

ignition_field_builder

Step 2: Create an interface for the field in Visual Studio

  1. If you do not already have a project for Ignition field customizations:
    1. create a new project in ./Ignition/Data/  and name it Ignition.Data.Custom
    2. Open the project’s properties. Set the default namespace to “Ignition.Data”.
    3. Add references to the Glass.Mapper, Glass.Mapper.Sc, and Ignition.Core assemblies.
  2. Navigate to Ignition/Data/Ignition.Data.Custom/Fields. (If this directory does not exist, create it)
  3. Create a new interface called IDateField3, using the following snippet as a guide:
using System;
using Glass.Mapper.Sc.Configuration.Attributes;
using Ignition.Core.Models.BaseModels;
namespace Ignition.Data.Fields
{
   [SitecoreType(TemplateId = "{60B802C3-699A-4B0E-8411-69DC59642F4E}")]
   public interface IDateField3 : IModelBase
   {
       [SitecoreField(FieldId = "{5F499660-F29A-4372-BDA4-4A387FE13BF2}")]
       DateTime DateField3 { get; set; }
   }
}

Notes:

  • The FieldId property enables you to cast items to this type from base classes (e.g. an IModelBase coming back as the datasource). If the FieldId property is missing, the casting will not work.
  • The GUIDs are generated pseudo-randomly, so your template ID and field ID will not match the IDs given in this example. You must manually copy your own IDs from Sitecore to this interface in Visual Studio.

ignition_field_guids

Finishing up

Build the Ignition.Data.Custom project and re-publish. The newly-created field should now be usable on all Ignition-based templates.
For more information about using the Ignition framework please click the following link: http://sitecoreignition.readthedocs.io/en/master/
This online documentation is still in progress and will be updated with the latest information when available.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Jacob King

Jacob King is a Senior Technical Consultant for Perficient, specializing in Sitecore solutions. He lives in Indianapolis with his wife and son.

More from this Author

Categories
Follow Us