In this chapter, learn how to model content and build a schema with Content Fragment Models. You learn about the different data types that can be used to define a schema as part of the model.
We create two simple models, Team and Person. The Team data model has name, short name, and description and references the Person data model, which has full name, bio details, profile picture, and occupations list.
You are also welcome to create your own model following the basic steps and tweak the respective steps like GraphQL queries, and React App code or simply follow the steps outlined in these chapters.
This is a multi-part tutorial and it is assumed that an AEM author environment is available.
A project configuration contains all Content Fragment models associated with a particular project and provides a means of organizing models. At least one project must be created before creating Content Fragment Model.
Login to the AEM Author environment (ex. https://author-pYYYY-eXXXX.adobeaemcloud.com/
)
From the AEM Start screen, navigate to Tools > General > Configuration Browser.
Click Create, in the top-right corner
In the resulting dialog, enter:
Next, create two models for a Team and a Person.
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:
fullName
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:
biographyText
Click the Data Types tab and drag and drop a Content Reference field. Enter the following properties:
profilePicture
/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:
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 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:
title
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:
shortName
^[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:
description
Click the Data Types tab and drag and drop a Fragment Reference field. Enter the following properties:
teamMembers
The final Team model should look like the following:
Click Save to save the changes.
You should now have two models to work from:
Upon review and verification, publish the Project Configuration
& Content Fragment Model
From the AEM Start screen, navigate to Tools > General > Configuration Browser.
Tap the checkbox next to My Project and tap Publish
From the AEM Start screen, navigate to Tools > General > Content Fragment Models.
Navigate into the My Project folder.
Tap Person and Team models and tap Publish
Congratulations, you just created your first Content Fragment Models!
In the next chapter, Authoring Content Fragment Models, you create and edit a new Content Fragment based on a Content Fragment Model. You also learn how to create variations of Content Fragments.