Content-Type (Schema/Object-Type)
This explains Content-Types. For an overview check out Understanding Data....
What is a Content-Type?
Every Entity (thing, record or object) in 2sxc has a definition of fields it can have. So a Book
may have fields like Name, Author, Title etc.
The Content-Type will define what fields exist, what is required and what order the fields will appear in when editing the item.
This definition of the Type is called a Content-Type and it contains specs as to the exact fields are used and what their field-types are.
Other systems may call this Schema, Object-Type, Object-Structure or Table Definition
Tip
Before you start: Remember that you usually don't need this if you are creating Razor templates or WebApi - for that, you want to read Dynamic Entity Objects.
Where are Content-Types
- App Content-Types - this is the default, these Types are part of an App
- App Shared Content-Types - for advanced use cases
- System Content-Types - included in the default installation
- Global Shared Content-Types - for very advanced use cases
What's Defined in a Content-Type?
Content-Types are a configuration which contains:
- The list of fields the Content-Type has with the technical name, like
ProfilePhoto
- Edit-UI information for the edit form
- The order of the fields should be shown in when editing
- A user friendly name like
Profile Photo
and editing help texts likeThis should only contain head & shoulders
- The Input-Type which the UI should show, like
Hyperlink
(which means that it's a link or file) - Input-Type configuration, for example
AllowUpload
etc.
- Optionally some of the Edit-UI information in more languages like
Profilbild
in German - Optionally permission information like May be used in Mobile Apps for read-only
Nice to Know: Edit Content-Types
- Content-Types are configured in the App-Management UIs
- You can create new Content-Types at any time
- You can rename a Content-Type at any time
- If you change the display-name (like
Blog Post
toBlog Entry
) then your code doesn't need changes. - If you change the technical name (
BlogPost
toBlogEntry
) then your code needs to be updated
- If you change the display-name (like
- You can delete Content-Types at any time
When you delete a Content-Type, all Entities/Items of that type are deleted - Content-Types have additional descriptions and help-texts which are shown in the Edit-UI
- Content-Types can also have an icon, but that's only used in Content Mode
Nice to Know: Edit Fields of a Content-Type
- You can always create new fields on a Content-Type
When you add new fields, then existing data will have that field, but no values on these fields - You can always delete existing fields on a Content-Type
When you remove fields, existing data will lose those values - You can always rename fields of a Content-Type
- When you change the display name of a field (like
Persons Photo
toProfile Picture
) the technical field name doesn't change, so your code doesn't need modification. - If you change the technical field name (like
ProfilePic
toProfilePhoto
) the code must be updated
- When you change the display name of a field (like
Nice to Know: Export / Import Content-Type Definition
- You can export a Content-Type into a JSON format
- You can import the Content-Type into another App using upload or drag-n-drop
Important
Exporting the Content Type Definition exports the schema / fields of that type.
Exporting all the Items of a Content-Type is a table-export of all the data.
Content-Type - More Information
Identity of a Content Type: Name and StaticName
Each content-type has a Name, which is nice for a human to read, use and program with. There is a second identifier called StaticName which is usually a GUID, but in rare cases it's a string like App-Settings
. This identifier is used internally - for example when a View references a Content-Type.
Storage
Most Content-Types in your App are stored in the SQL database. System and global Content-Types are stored in the file system. These are called File-Stored Content-Types
Field Types
Each field will be of a simple type like text/string, number, boolean (yes/no) or other. You can find the list of types here.
Relationships
Fields can also be of type Entity in which case they point to other items. This would then establish a Relationship
Input Forms and Fields (like WYSIWYG)
The input mask is automatically generated from the Content-Type. Based on the specifications, it will generate the correct Input-Field like a simple text field, a multiline text field, a WYSIWYG or even a file-uploader.
Scopes
Content-Types have a Scope. Read about it Content-Type Scopes
APIs
- ToSic.Eav.Data Namespace has almost everything you see here
- IContentType defines what fields exist, it's the ContentType / Schema
- IContentTypeAttribute contains the definition of an attribute
- ContentTypeMetadata, IMetadataOf
contains information about the content-type (like nicer descriptions). This is also used for the Attribute-Metadata
History
- Introduced in 2sxc 1.0