Create Content Fragment Models
Next, create two models for a Team and a Person.
Create the Person Model
Create a model for a Person, which is the data model representing a person that is part of a team.
-
From the AEM Start screen, navigate to Tools > General > Content Fragment Models.
-
Navigate into the My Project folder.
-
Tap Create in the top-right corner to bring up the Create Model wizard.
-
In Model Title field, enter Person and tap Create. In the resulting dialog, tap Open, to build the model.
-
Drag and Drop a Single line text element on to the main panel. Enter the following properties on the Properties tab:
- Field Label: Full Name
- Property Name:
fullName
- Check Required
The Property Name defines the name of the property that is persisted to AEM. The Property Name also defines the key name for this property as part of the data schema. This key is used when the Content Fragment data is exposed via GraphQL APIs.
-
Tap the Data Types tab and drag and drop a Multi line text field beneath the Full Name field. Enter the following properties:
- Field Label: Biography
- Property Name:
biographyText
- Default Type: Rich Text
-
Click the Data Types tab and drag and drop a Content Reference field. Enter the following properties:
- Field Label: Profile Picture
- Property Name:
profilePicture
- Root Path:
/content/dam
When configuring the Root Path, you can click the folder icon to bring up a modal to select the path. This restricts which folders authors can use to populate the path.
/content/dam
is the root in which all AEM Assets (images, videos, other Content Fragments) are stored. -
Add a validation to the Picture Reference so that only content types of Images can be used to populate the field.
-
Click the Data Types tab and drag and drop an Enumeration data type beneath the Picture Reference field. Enter the following properties:
- Render As: Checkboxes
- Field Label: Occupation
- Property Name:
occupation
-
Add several Options using the Add an option button. Use the same value for Option Label and Option Value:
Artist, Influencer, Photographer, Traveler, Writer, YouTuber
-
The final Person model should look like the following:
-
Click Save to save the changes.
Create the Team Model
Create a model for a Team, which is the data model for a team of people. The Team model references the Person model to represent the members of the team.
-
In the My Project folder, tap Create in the upper right corner to bring up the Create Model wizard.
-
In Model Title field, enter Team and tap Create.
Tap Open in the resulting dialog, to open the newly created model.
-
Drag and Drop a Single line text element on to the main panel. Enter the following properties on the Properties tab:
- Field Label: Title
- Property Name:
title
- Check Required
-
Tap the Data Types tab and drag and Drop a Single line text element on to the main panel. Enter the following properties on the Properties tab:
- Field Label: Short Name
- Property Name:
shortName
- Check Required
- Check Unique
- Under, Validation Type > choose Custom
- Under, Custom Validation Regex > enter
^[a-z0-9\-_]{5,40}$
- this ensures that only lowercase alphanumeric values and dashes from 5 through 40 characters can be entered.
The
shortName
property provides us a way to query an individual team based on a shortened path. The Unique setting ensures that the value is always unique per Content Fragment of this model. -
Tap the Data Types tab and drag and drop a Multi line text field beneath the Short Name field. Enter the following properties:
- Field Label: Description
- Property Name:
description
- Default Type: Rich Text
-
Click the Data Types tab and drag and drop a Fragment Reference field. Enter the following properties:
- Render As: Multiple Field
- Field Label: Team Members
- Property Name:
teamMembers
- Allowed Content Fragment Models: Use the folder icon to select the Person model.
-
The final Team model should look like the following:
-
Click Save to save the changes.
-
You should now have two models to work from: