Consider the following requirement: A company has several products and each product has several sub-types called grades. Each grade has several properties, some of them specific to the grade. It is required to load grade and property data into Sitecore and be able to display the grades and their properties for a selected product.
An elegant way to implement this requirement is by developing a custom field type that can store the different, multiple properties passed in as parameters. These properties can then be retrieved by referencing a single item rather than having to access several items. An outline of the solution is presented below.
Step 1: Create a .NET class for field type
The class name will be the field type name. We inherit from Sitecore.Web.UI.HtmlControls.Control as the base class.
Step 2: Custom field type implementation
Write the code to process the properties, separated by a delimiter, and render them as individual fields as shown below.
The grade properties values will be stored as name value pairs separated by ‘=’.
Step 3: Add config file
Create the required configuration file in App_Config\Include folder to reference the custom field type by its class.
Step 4: Create a new Field in Sitecore
Create a new field type based on the template “Template field type” in the Core database and specify the “Control” field to refer to the class name in Step 1.
Step 5: Add field belonging to the new field type on a template and create item
The new field type then works similar to any built-in type in terms of specifying it on a template.
If you would like more help on Sitecore Custom Field Type Implementation Contact Us Today.