In this chapter learn how to model content and build a schema with Content Fragment Models. You will review existing models and create a new model. You will also learn about the different data types that can be used to define a schema as part of the model.
In this chapter you will create a new model for a Contributor, which is the data model for those users that author magazine and adventure content as part of the WKND brand.
This is a multi-part tutorial and it is assumed that the steps outlined in the Quick Setup have been completed.
The above video gives a high level overview of working with Content Fragment Models.
The above video shows the creation of the Contributor model with the name
Contributors. When performing the steps in your own environment, ensure that the title uses the singular form:
Contributor without the s. The naming of the Content Fragment Model drives the GraphQL API calls that will be performed later in the tutorial.
In the previous chapter several Adventures Content Fragments were edited and displayed on an external application. Let’s inspect the Adventure Content Fragment Model to understand the underlying data schema of these fragments.
From the AEM Start menu navigate to Tools > Assets > Content Fragment Models.
Navigate into the WKND Site folder and hover over the Adventure Content Fragment Model and click the Edit icon (pencil) to open the model.
This opens the Content Fragment Model Editor. Observe that the fields define the Adventure model include different Data Types like Single line text, Multi line text, Enumeration, and Content Reference.
The right-hand column of the editor lists the available Data Types which define the form fields used for authoring Content Fragments.
Select the Title field in the main panel. In the right-hand column click the Properties tab:
Observe the Property Name field is set to
adventureTitle. This 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 will be used when the Content Fragment data is exposed via GraphQL APIs.
Modifying the Property Name of a field after Content Fragments are derived from the Model, has downstream effects. Field values in existing fragments will no longer be referenced and the data schema exposed by GraphQL will change, impacting existing applications.
Scroll down in the Properties tab and view the Validation Type dropdown.
Out of the box form validations are available for E-mail and URL. It is also possible to define a Custom validation using a regular expression.
Click Cancel to close the Content Fragment Model Editor.
Next, create a new model for a Contributor, which is the data model for those users that author magazine and adventure content as part of the WKND brand.
Click Create in the upper right corner to bring up the Create Model wizard.
For Model Title enter: Contributor and click Create
Click Open 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:
Click the Data Types tab and drag and drop a Multi line text field beneath the Full Name field. Enter the following properties:
Click the Data Types tab and drag and drop a Content Reference field. Enter the following properties:
When configuring the Root Path you can click the folder icon to bring up a modal to select the path. This will restrict which folders authors can use to populate the path.
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:
Add several Options using the Add a option button. Use the same value for Option Label and Option Value:
Artist, Influencer, Photographer, Traveler, Writer, YouTuber
The final Contributor model should look like the following:
Click Save to save the changes.
Content Fragment Models need to be Enabled before content authors can use it. It is possible to Disable a Content Fragment Model, thus prohibiting authors from using it. Recall that modifying the Property Name of a field in the model changes the underlying data schema and can have significant downstream effects on existing fragments and external applications. It is recommended to carefully plan the naming convention used for the Property Name of fields before enabling the Content Fragment Model for users.
Ensure that the Contributor model is currently in an Enabled state.
It is possible to toggle a Content Fragment Model’s state by hovering over the card and clicking the Disable / Enable icon.
Congratulations, you just created your first Content Fragment Model!
In the next chapter, Authoring Content Fragment Models, you will create and edit a new Content Fragment based on a Content Fragment Model. You will also learn how to create variations of Content Fragments.