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
- Create a new template in
/sitecore/templates/Ignition/Fields/Content
. - Name the template
DateField3
. - For the base template, select
Templates/Ignition/ItemBase
. - Assign your new template an icon. (For this example we will use
Business/32x32/calendar.png
) - On the template’s builder tab, create a section called
Content
and create the fieldDateField3
of typeDatetime
.
Step 2: Create an interface for the field in Visual Studio
- If you do not already have a project for Ignition field customizations:
- create a new project in
./Ignition/Data/
and name itIgnition.Data.Custom
- Open the project’s properties. Set the default namespace to “Ignition.Data”.
- Add references to the
Glass.Mapper, Glass.Mapper.Sc
, andIgnition.Core
assemblies.
- create a new project in
- Navigate to
Ignition/Data/Ignition.Data.Custom/Fields
. (If this directory does not exist, create it) - 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.
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.