Content Fragments
Content fragments allow you to design, create and publish the page independent content.
What is Page independent content?
Suppose you have a page and you need some content on that page so you will create that content on the page. But if you need the same content on the different-different pages what you need to you need to create the same content on different-2 pages but this is not a good approach. We should have capabilities to reuse the content as well as we are using the AEM as a CMS.
- As per the content fragment you will create a content fragment with the content that you need on the pages and you will reuse that content on different-2 pages mean you can reuse the content.
- Content fragment allows you to create the different-2 variation of same content.
- Content fragment are editorial content primarily text and images. It is pure content it doesn't have any styling and layout.
- Content fragment allows you to create the channel specific content along with the variation.
- There is one OOTB(Out of the Box ) Component came in the core components is known as Content Fragment Component. You can use this component to display the content from content fragment.
- Content fragment also delivered the content in JSON format It uses the sling.
Architecture of content fragment
- We will be needing a content fragment model and in the CF model we will define the fields and its type.
- In this step you will create a content fragment from the content fragment model that you created in step 1. Now those fields will be available to add the content.
- You can create the different-2 variation of the content like in variation 1 you can have different data and in variation 2 you can have different data.
- To use this content fragment you have to use the content fragment model that come OOTB. And you can create your own component as well.
- You will use this Content fragment component on pages .
- You can export the content fragment in Raw JSON format and you can use this data in any third party application.
1.Content Fragment Model Or How to create the Content Fragment Model
- To create content fragment model go to tools>Assets>Content Fragment Model or click here to go
- Check either you are able to see your project specific folder here or not if yes than no need to perform any other step.
- If you are not able to see you project specific folder in the content fragment model than go to the Tools>general>configuration browser
- In the configuration browser you will be able to see your project specific folder. Select it and go to the properties of that folder
- Open the properties and you will be able to see the properties like
- Select the checkbox of content fragment models and click on save and close.
- Now you will be able to see you project specific folder inside the content fragment models.
- One case can be your project was created through old archetype in this case you may need to create the folder manually here and at last can add that folder in your code base.
- Go in the Tools>assets>content fragment model and go inside your project specific folder.
- And you will be able to see
- Click on create and create your content fragment model and edit it like
- In LHS canvas you can drag and drop the field from RHS and from properties tab you can change the properties from properties tab.
- Click on save .
- Now your content fragment model is ready with the fields.
Note:-By default your content fragment model will be Enable.
How to create the Content Fragment and use it on the Page?
- Go to the Navigation>Assets>Files>Project Specific Folder like
- The content fragment will store in Navigation>Assets>files>Project specific folder.
- Ans in JCR the content fragment will store in the /content/dam/project-specific-folder/content-fragments like
- Go to the Navigation>Assets>files>Project specific folder and you will be get an option to create the content fragment like click on create button
- After clicking on create you will get an option to create the content fragment
- Click on Content Fragment and you will get
- I am not able to see my content fragment model that I have created but I am not getting . To resolve this issue go to the Navigation>Assets>files>Project specific folder select the folder and go to the properties of folder like
- Select the properties and go to the Policies Tab
- And select content fragment models that you want to allow and click on save and close.
- Now again try to create the content fragment and I am able to see the content fragment models that I created
- Select your content fragment model click on Next and give the title like
- Open it. And now my content fragment looks like
- Author it like
- Click on Save.
- Now Content Fragment is ready to use.
How to use the content Fragment on the Page?
To render the content fragment's data on the page we have to use the content fragment component that comes OOTB.
Content Fragment OOTB Component
We should not use this component directly in our project. We will check the content fragment component in our project if it will not present there we will create a proxy component. But it is present in our project
Copy the path and append .json on the last and append it with http://localhost:4502/{path till component node}+{.json}
- Will create a page and drag & Drop the content fragment component.
- When I am trying to author the component I am getting this dialog
- In first path field we have to choose the path of the content fragment.
- I have authored the path of my content fragment in the content fragment component like
- And I can see the the data on the page that I authored in the content fragment like
- Display Mode:-We have two display mode in the content fragment component one is single line and another is multi line. In Multi line the component will display the all data authored in the content fragment.
- And in case of single line we have to choose what field we want to display on the page. We can choose more than one field as well like
- Variation means in different-2 variation you will have different-2 data. If you will change the variation from the CF Component the content will be change. Let us check.
- The ID Field in the content fragment component is for giving the HTML ID in case you want to apply and CSS.
Export the Content Fragment's Content Or How to export the content fragment's content to third party system?
We can export the content fragments by using two ways
- Sling Exporters.
- Assets API.
Let us see first how can we export the content using Sling Model Exporter Capabilities.
Copy the component path till component node in the page's jcr:content
For example:http://localhost:4502/content/aem-pro/en/homepage/osgi-service-test/jcr:content/root/responsivegrid/container/layoutcontainer/contentfragment.json
- If we are adding the .json extension at last in the URL we are getting all the data but we want only the content that we authored in our content fragment so we have to add .model.json extension at last like(http://localhost:4502/content/aem-pro/en/homepage/osgi-service-test/jcr:content/root/responsivegrid/container/layoutcontainer/contentfragment.model.json)
- Now we are getting our content fragment's specific data
- What variation you will use and you export the content using Sling Exporter you will be able to see only that variation's content that you authored in the component.
How to export the content of content fragment with Assets API?
- Open the content fragment in edit mode and replace (/editor.html/content/dam with /api/assets)in the URL the like and add .json at last for example(http://localhost:4502/api/assets/aem-pro/content-fragment-for-demo.json)
Difference between the Sling Exporter and Assets API in terms of content fragment?
The main difference is Sling Export export only that content that we are using on the page. But using Assets API you can have all the data including master and other variations.
No comments:
Post a Comment