Field templates
A field template is a set of fields that describe a type of an entity.
For example a product type like sweaters, or in a completely different scenario, a phone. To describe sweaters and phones, we need different sets of fields set up in field templates.
All entities that have fields, also have field templates.
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.
In a product field template, fields can be specified for both the base product and a variant.
Values for fields that are not included in any field template can 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);
}
}