Defining your Content Fragment Model
The content fragment model effectively defines the structure of the resulting content fragments using a selection of Data Types. Using the model editor you can add instances of the data types, then configure them to create the required fields:
-
Navigate to Tools, General, then open Content Fragment Models.
-
Navigate to the folder holding your content fragment model.
-
Open the required model for Edit; use either the quick action, or select the model and then the action from the toolbar.
Once open the model editor shows:
- left: fields already defined
- right: Data Types available for creating fields (and Properties for use once fields have been created)
NOTE
When a field as Required, the Label indicated in the left pane is marked with an asterix (*).
-
To Add a Field
-
Drag a required data type to the required location for a field:
-
Once a field has been added to the model, the right panel will show the Properties that can be defined for that particular data type. Here you can define what is required for that field.
-
Many properties are self-explanatory, for additional details see Properties.
-
Typing a Field Label will auto-complete the Property Name - if empty, and it can be manually updated afterwards.
CAUTION
When manually updating the property Property Name for a data type, note that names must contain only A-Z, a-z, 0-9 and underscore “_” as special character.If models created in earlier versions of AEM contain illegal characters, remove or update those characters.
For example:
-
-
-
To Remove a Field
Select the required field, then select the trash-can icon. You are asked to confirm the action.
-
Add all required fields, and define the related properties, as required. For example:
-
Select Save to persist the definition.
Data Types
A selection of data types is available for defining your model:
-
Single line text
- Add a field for a single line of text; the maximum length can be defined
- The field can be configured to allow fragment authors to create new instances of the field
-
Multi line text
- A text area that can be Rich Text, Plain Text, or Markdown
- The field can be configured to allow fragment authors to create new instances of the field
NOTE
Whether the text area is Rich Text, Plain Text, or Markdown, is defined in the model by the property Default Type.This format cannot be changed from the Content Fragment editor, but only from the Model. -
Number
- Add a numerical field
- The field can be configured to allow fragment authors to create new instances of the field
-
Boolean
- Add a boolean checkbox
-
Date and time
- Add a date and/or time field
-
Enumeration
- Add a set of Checkbox, Radio Button, or Dropdown fields
- You can specify the options available to the fragment author
- Add a set of Checkbox, Radio Button, or Dropdown fields
-
Tags
- Allows fragment authors to access and select areas of tags
-
Content Reference
- References other content, of any type; can be used to create nested content
- If an image is referenced, you can opt to show a thumbnail
- The field can be configured to allow fragment authors to create new instances of the field
-
Fragment Reference
-
References other Content Fragments; can be used to create nested content
-
The field can be configured to allow fragment authors to:
- Edit the referenced fragment directly
- Create a new Content Fragment, based on the appropriate model
- Create new instances of the field
-
-
JSON Object
-
Allows the Content Fragment author to enter JSON syntax into the corresponding elements of a fragment.
- To allow AEM to store direct JSON that you have copy/pasted from another service.
- The JSON is passed through, and output as JSON in GraphQL.
- Includes JSON syntax-highlighting, auto-complete, and error-highlighting in the Content Fragment editor.
-
-
Tab Placeholder
-
Allows the introduction of tabs for use when editing the Content Fragment content.
- These are shown as dividers in the model editor, separating sections of the list of content data types. Each instance represents the start of a new tab.
- In the fragment editor each instance appears as a tab.
NOTE
This data type is purely used for formatting, it is ignored by the AEM GraphQL schema.
-
Properties
Many properties are self-explanatory, for certain properties additional details are below:
-
Property Name
When manually updating this property for a data type, note that names must contain only A-Z, a-z, 0-9 and underscore “_” as special character.
CAUTION
If models created in earlier versions of AEM contain illegal characters, remove or update those characters. -
Render As
The various options for realizing/rendering the field in a fragment. Often this property lets you define whether the author sees a single instance of the field, or is allowed to create multiple instances. When Multiple Field is used you can define the minimum and maximum number of items - see Validation for further details. -
Field Label
Entering a Field Label will autogenerate a Property Name, which can then be manually updated if necessary. -
Validation
Basic validation is available by mechanisms such as the Required property. Some data types have addition validation fields. See Validation for further details. -
For the data type Multi line text it is possible to define the Default Type as either:
- Rich Text
- Markdown
- Plain Text
If not specified, the default value Rich Text is used for this field.
Changing the Default Type in a content fragment model will only take effect on an existing, related, content fragment after that fragment is opened in the editor and saved.
-
Unique
Content (for the specific field) must be unique across all content fragments created from the current model.This is used to ensure that content authors cannot repeat content already added in another fragment of the same model.
For example, a Single line text field called
Country
in the Content Fragment Model cannot have the valueJapan
in two dependent Content Fragments. A warning is issued when the second instance is attempted.NOTE
Uniqueness is ensured per language root.NOTE
Variations can have the same unique value as variations of the same fragment, but not the same value as used in any variation of other fragments.CAUTION
If you want to use MSM (which creates copies of Content Fragments), then any Unique constraints should be removed from any Data Types used in the respective Content Fragment Models. -
See Content Reference for more details about that specific data type and its properties.
-
See Fragment Reference (Nested Fragments) for more details about that specific data type and its properties.
-
Translatable
Checking the Translatable checkbox on a field in the Content Fragment Model editor will:
- Ensure the field’s property name is added to the translation configuration, context
/content/dam/<sites-configuration>
, if not already present. - For GraphQL: set a
<translatable>
property on the Content Fragment field toyes
, to allow GraphQL query filter for JSON output with only translatable content.
- Ensure the field’s property name is added to the translation configuration, context
Validation
Various data types now include the possibility to define validation requirements for when content is entered in the resulting fragment:
-
Single line text
- Compare against a predefined regex.
-
Number
- Check for specific values.
-
Content Reference
- Test for specific types of content.
- Only assets of specified file size or smaller can be referenced.
- Only images within a predefined range of width and/or height (in pixels) can be referenced.
-
Fragment Reference
- Test for a specific content fragment model.
-
Min Number of Items / Max Number of Items
Fields that have been defined as a Multiple Field (set with Render As) have the options:
- Min Number of Items
- Max Number of Items
These are validated:
- The max value is validated in the original Content Fragment Editor.
- Both are validated in the Content Fragment Editor.
Using References to form Nested Content
Content Fragments can form nested content, using either of the following data types:
-
- Provides a simple reference to other content; of any type.
- Can be configured for a one or multiple references (in the resulting fragment).
-
Fragment Reference (Nested Fragments)
-
References other fragments, dependent on the specific models specified.
-
Lets you include/retrieve structured data.
NOTE
This method is of particular interest in conjunction with Headless Content Delivery using Content Fragments with GraphQL.* Can be configured for one or multiple references (in the resulting fragment)..
-
-
Content References
This prevents the user from adding a reference to the current fragment. This may lead to an empty Fragment Reference picker dialog. -
Fragment References in GraphQL
If you create a deep query that returns multiple Content Fragments referenced by each other, it will return null at first occurrence.