AEM Content Fragment
Content fragment allows us to publish structured content on third party channels depending on various layouts.
Content fragment is a data model based on schema to collect data such as text and image.
It can be used content as a service to expose content fragment in the form JSON using JSON exporter to third party systems.
Please follow this link to read more about JSON exporter.
Content fragment can also be used as headless CMS where we can expose content fragment data using JSON exporter to third party system as mentioned in earlier steps.
There are two ways to create content fragment:
- Using simple content fragment template.
- Using content fragment model to create structured content.
Simple Content Fragment Template
Fragment created using simple fragment template will only allow to author text and image.
Follow below steps to create content fragment:
1. Go to sites.html page and click on navigation -> Assets as shown below:
2. Click on files and go to specific folder to create a content fragment. Click on create button and select Content Fragment option.
3. Select Simple Fragment template and click on Next button.
4. Provide required custom title and click on Create button.
5. Author title and image in content fragment.
6. Consume content fragment as JSON → Hit below URL to consume content fragment as JSON which can be consume by third party systems:
http://localhost:4502/content/dam/practice/practice-content-fragment/_jcr_content/model.json
7. Consume content fragment as HTML → Create page, select Drag Components here.
Drag and drop Content Fragment component on the page.
Select content fragment and its variation as master.
Note: Content Fragment always creates first variation as master by default.
Click on ok after authoring will give below output:
Structured Content Fragment
Fragment created using content fragment model will contain text, image , date, references, etc.
Using content fragment model we can create structure content.
This can be used content as a service using JSON exporter.
Below are the steps to create Structured content fragment:
- Click on tools -> Assets -> Content Fragment Models to create a Content Fragment Model and define its structure.
2. Go to specified folder structure and click on Create button to create a Content Fragment Model
3. Provide title and click on Create button will finally create content fragment model
4. Drag and drop required data types to created content fragment and its structure as shown below. For example, drag and drop single line text field and provide value highlighted red in color.
Do the Same with other required fields also.
5. Click on Save button after drag, drop and filling all required information will complete the process to create content fragment model.
Content Fragment will get create inside below hierarchy:
/conf/practice/settings/dam/cfm/models/practice-structured-content-fragment
6. Now, its time to create structured content. Navigate to sites.html page and click on navigation -> Assets as shown below:
7. Click on files and go to specific folder to create a content fragment. Click on create button and select Content Fragment option.
8. Select Practice Structured Content Fragment template and click on Next button to provide information related content fragment.
9. Provide content fragment title and click on Create button
10. Fill Name, Address, Age and click on save button will create content fragment.
11. Consume content fragment as JSON → Hit below URL to consume content fragment as JSON which can be consume by third party systems:
http://localhost:4502/content/dam/practice/practice-content-fragment/_jcr_content/model.json
12. Consume content fragment as HTML → Drag and drop content fragment component on the page, provide required content fragment path and its variation. Click on ok will author content fragment on the page.
13. After successful authoring will give below view on the page.
I hope you found out this article interesting and informative. Please share it with your friends to spread the knowledge.
You can follow me for upcoming blogs follow.
Thank you!