Field framework

The field framework is used to handle fields and field data. The name of a product is an example of a field in the field framework. The field framework is designed to support all types of information, from simple text fields to custom fields that cover a special case in the solution. It is divided into field types, field definitions, field templates and in some cases display templates.

Field types

The field type is the lowest level in the field framework and handles how fields are loaded or persisted in the data store. The field type is also responsible for creating the correct filter on the field from querying in data service.

Custom field types can be created and added to the solution, read more about how to extend here.

Field types are global and not bound to a specific part of Litium.

Field definitions

Field definitions are created to define the type of a field. For example, "Name" is a field of the type “text”. The field definition contains settings on the instance of the field, for example multi language for fields that can have values in multiple languages.

Field definitions are specific to different areas (formerly known as modules) of Litium. If you try to save a field that doesn't exist as a field definition in the current area of Litium, an exception will be thrown.

using System;
using Litium.Products;
public class FieldDefinitionExample
{
    private readonly FieldDefinitionService _fieldDefinitionService;
    private readonly BaseProductService _baseProductService;

    public FieldDefinitionExample(FieldDefinitionService fieldDefinitionService, BaseProductService baseProductService)
    {
        _fieldDefinitionService = fieldDefinitionService;
        _baseProductService = baseProductService;
    }

    public void CreateFieldDefinition()
    {
        var fieldDefinition = new FieldDefinition("MyField", "text")
        {
            Localizations =
            {
                ["sv-SE"] = {Name = "Mitt fält", Description = "Mitt fält för att spara information"},
                ["en-UK"] = {Name = "My field", Description = "My field to save information"},
            },
            CanBeGridColumn = false,
            CanBeGridFilter = true,
        };
        _fieldDefinitionService.Create(fieldDefinition);
    }

    public void CreateField()
    {
        Guid fieldTemplateSystemId;
        var baseproduct = new BaseProduct("My_baseproduct", fieldTemplateSystemId);
        baseproduct.Fields.AddOrUpdateValue("MyField", "value");
        _baseProductService.Create(baseproduct);
        
        var myFieldValue = baseproduct.Fields.GetValue<string>("MyField");
    }

    public void UpdateField()
    {
        var baseproduct = _baseProductService.Get("My_baseproduct");
        var changableBaseProduct = baseproduct.MakeWritableClone();
        changableBaseProduct.Fields.AddOrUpdateValue("MyField", "value2");
        _baseProductService.Update(changableBaseProduct);
    }
}

Field templates

Field templates are used to decide what an administrator, and in some cases public visitors, will see. Field templates are specified for each entity. For example for a category or a product.

In a product field template, fields can be specified for both the base product and variant. One field can exist in multiple field groups and only specifies if, and where, the field should be visible in the administration view or on the public site.

Values for fields that are not included in any field template can still be set through the API.

    using System;
    using Litium.Products;
    public class FieldTemplateExample
    {
        private readonly FieldTemplateService _fieldTemplateService;

        public FieldTemplateExample(FieldTemplateService fieldTemplateService)
        {
            _fieldTemplateService = fieldTemplateService;
        }

        public void Main()
        {
            Guid displayTemplateId;
            var fieldTemplate = new ProductFieldTemplate("MyFieldTemplate", displayTemplateId)
            {
                Localizations =
                {
                    ["se-SV"] = {Name = "Min fältmall"},
                    ["en-UK"] = {Name = "My field template"}
                },
                ProductFieldGroups =
                {
                    new FieldTemplateFieldGroup
                    {
                        Localizations =
                        {
                            ["se-SV"] = {Name = "Min grupp"},
                            ["en-UK"] = {Name = "My group"}
                        },
                        Fields =
                        {
                            "MyField1",
                            "MyField2",
                            "MyField3"
                        }
                    }
                },
                VariantFieldGroups =
                {
                    new FieldTemplateFieldGroup
                    {
                        Localizations =
                        {
                            ["se-SV"] = {Name = "Min grupp"},
                            ["en-UK"] = {Name = "My group"}
                        },
                        Fields =
                        {
                            "MyField8",
                            "MyField2",
                            "MyField5"
                        }
                    }
                }
            };

            _fieldTemplateService.Create(fieldTemplate);
        }
    }

Display templates

A display template is a definition of how the rendering should work. For example the actual template that should be used (WebForm ASPX file of MVC Controller).

For Products, the display template also decides if variants should be exposed as separate items with their own URL on the public site, or if they all should be exposed as a product family with one URL.

Is this page helpful?
Thank you for your feedback!