Field Models are defined inside of Content Models - They define individual fields.
A field model describes the name and the type of a field, as well as its presentation and behavior inside a CMS UI editor.
A field model is an array of objects defining the names, types, labels, descriptions, etc. of the content models fields. Fields can have different types (string, boolean, list, object, name of an object model, and etc.), can be required or optional, hidden, can have default values and etc.
Field Model Schema
|type||required||Name of any valid type (e.g.: |
|name||required||The field key as it should appear in the content||Should contain only alphanumeric characters, underscore and a hyphen |
|label||required||Human readable label for the field||Should be short enough as some CMS's have restrictions on its length|
|description||optional||Short description to editors how the field is to be used|
|required||optional||Defines if the field should be required|
|default||optional||The default value for this field that will be placed inside the UI editor.||This is not a fallback value that will be used if the field is not set or empty. In some CMS's this is only a UI editor feature, meaning that the default value will be set only if it is not hidden. Therefore this field must not be used for required values, use |
|const||optional||The constant value that should be set when the object is created.||If this type of field is not supported by CMS's, its behavior could be achieved by using |
|hidden||optional||Defines if the field should be hidden from the editor.||When hiding fields, CMS's might not set the field's |
|readOnly||optional||Defines if the field should be readonly. This property could be used if a field value is not a constant and created outside of CMS UI (e.g.: imported via API).||For CMS's not supporting this property, a combination of |
|unique||optional||Defines if the field value should be unique||Not in use yet.|
Not supported in many CMS's. Unique between same model type, or across all models?
|widget||optional||Defines the UI of field control (textfield, textarea, select, checkbox, etc.)||not in use yet|
|validations||optional||To be defined||not in use yet.|
Currently field validations are based on their types, the
Field Model Types
|Type||Description||Type Specific Properties|
|string||Short plain text|
|markdown||Rich text that should be run through |
|enum||A value from a list of predefined values|
|boolean||A boolean |
|image||Path to image file. When content is imported into CMS, images will be uploaded first, then, this value will be replaced with CMS specific value such as a returned asset ID or an object referencing the uploaded image.|
|file||Path to any file. Like with the |
|datetime||with date and time formatting options|
|date||with date formatting options|
|reference||A reference to a model of any of the types specified inside |
|object||A nested object. Some CMS's support only flat models. For these CMS's any nested objects will be transformed into a standalone model. Therefore, this type of field should be used only if the nested object is not repeated in another field. Otherwise, |
|<model_name>||Any other model of type |
|list||List of values|
|blocks||To be defined. A.K.A: rich-text (contentful), snippets (forestry), slices (prismic), block (sanity)|
models: action_block: type: object label: Action Block description: A block with title and action fields: - type: string name: title label: Title - type: reference name: action models: [action_button, action_image] action_button: type: object label: Action Button fields: - type: string name: label label: Button Label action_image: type: object label: Action Image fields: - type: image name: image label: Action Image Asset
A data represented by
action_block model with
actionBlock: title: "Find out more" action: type: "action_button" label: "click here"
A data represented by
action_block model with
actionBlock: title: "Find out more" action: type: "action_image" image: "/assets/images/find_more.png"
Field Model Naming Convention
- can only contain alphanumeric and a hyphen
-and an underscore
- must start with a letter
- must not start or end with hyphen
Special Field Models
Reference Type - a special type of field that defines which Object Models might be referenced by that field. Reference type can only reference "Object Models". A reference field can be used as an item type of a list field. Thus allowing to define list of objects of multiple types. The data of the referenced objects must include the
type field with value of the referenced model name.