Tuesday, 3 March 2020

Create Content Fragment in AEM

What is Content Fragment?

Content Fragments are editorial content, primarily text, and related images. They are pure content, without design and layout. Content fragments are not available in the classic UI. AEM also supports the translation of fragment content. Learn more about content fragments here.

Create Content Fragment Model Configuration:


Before we create content fragment we need to create a content fragment model. AEM configurations allow you to do many things such as editable templates, contextual site configurations, and content fragment configurations.
  1. Go to AEM Start > Tools > General > Configuration Browser > Create
  2. Enter “AEM Quickstart Site” for the title
  3. Check the “Content Fragment Models” checkbox
  4. Click create

Create a DAM Folder

Content fragments are stored in the AEM DAM and are simply treated as an asset like an image or pdf. We will want to create a DAM folder for storing all of our content fragments.
  1. Go to AEM Start > Assets > Files > Create > Folder
  2. Enter the title
  3. Click create

Map the configuration to the DAM folder

We need to map the configuration created in Step1 to the DAM folder so that we can create content fragments with custom schemas within this folder.
  1. Go to AEM Start> Assets > Files
  2. Edit the properties of the "AEM Quickstart Site" folder
  3. Go to the “Cloud Services” tab
  4. In the “Cloud Configuration” field select “AEM Quickstart Site”


Create a content fragment model

Let's create a content fragment model.
  1. Go to AEM Start> Tools > Assets > Content Fragment Models > AEM Quickstart Site > Create
  2. Set the title to “Demo Book” and then click “Open”.
  3. Add a single line text field with a field label of “Title” and a field name of “title”
  4. Add a single line text field with a field label of “Description and a field name of “description”
  5. Add a content reference field with the label “Image” and a field name of “image”
  6. Add a date and time field with a label of “Release Date” and a field name of “releaseDate”

Create a content fragment:

Now that we have configured the example project and created a movie model we can go ahead and create a movie content fragment. This will be the first entry in our headless CMS and will be reused in each of the four samples of this blog post.
  1. Go to AEM Start> Assets > Files > AEM Quickstart Site > Create > Content Fragment
  2. Select the Content Fragment Model i.e. "Demo Book"
  3. Enter a title for the book
  4. Click create
  5. Fill in the rest of the fields as desired

We can see below content fragment is created with content fragment model "Demo Book"

Render Content Fragments onto a page:

Content Fragments can be fetched onto a page by below different ways:

  1. Using AEM core components
  2. Using Custom Sling Model
  3. Using Servlet to access Content Fragment.

No comments :

Post a Comment