Create classification fields

To learn more about the different steps to create a custom field, read the For developers: Create custom fields for product types article.

Here is a list of the things that are specific for the classification field:

  • Field CLR type: The classification field does not use this parameter.
  • User friendly data type: UserFriendlyDataType.Classification
  • DB type: The classification field does not use this parameter.
  • Field type: typeof(HierarchicalTaxonomyField).FullName or typeof(FlatTaxonomyField).FullName

In addition, when creating a classification field you must perform the following:

  1. Get an instance of the taxonomy that is used by the field.
    To do this, you must call the GetTaxonomy method of the TaxonomyManager instance and pass the ID of the taxonomy as an argument.
  2. Skip the creating of a database mapping.
  3. Where creating the field definition set the following additional properties:
    • TaxonomyId
      Gets or sets the ID of the taxonomy that is used by the field.
    • AllowMultipleSelection
      Specifies whether the item will by classified by single taxon or by multiple taxa. Only the classification field requires this property. Set this property to true.
  4. Where creating the field definition set the FieldType property depending on the type of the taxonomy (flat or hierarchical).
  5. Skip the step where the database mappings are set.
  6. Set the following additional properties of the MetaField instance:
    • TaxonomyId
      Gets or sets the taxonomy used by field. Only the classification field requires this property.
    • TaxonomyProvider
      Gets or sets the provider of the taxonomy used by field. Only the classification field requires this property.
    • IsSingleTaxon
      Specifies whether the item will by classified by single taxon or by multiple taxa. Only the classification field requires this property.
  7. Add meta attribute ControlTag.
    This is the value of the attribute must be a taxonomy field control template. To get the value for the attribute, call the GetTaxonomyFieldControlTemplate static method and pass the name of the field and the instance of the taxonomy.

Here is a code example:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?