Wednesday, 12 December 2018

Steps to Create custom Content Fragment Templates in AEM 6.4

Hope you have gone through the basics of Content Fragments in AEM.
Create Content Fragments : Step By Step Tutorial

AEM 6.4 Content Fragment

[This tutorial works for versions AEM 6.2, AEM 6.3, AEM 6.4]

Generally AEM provides default content fragments template called 'Simple Fragment' [at location: /libs/settings/dam/cfm/templates]. But we may need to customize or create new templates based on our needs.

Here I will explain how we can create custom content fragment templates.

Where to create custom content fragment templates?


There are multiple places we can create custom content fragment templates.

  • Config: When we work with folder specific templates, use this location.
  • Apps: Usually general purpose templates are created here.


Content Fragment Templates Path


Let us create a template under /apps for general purpose use.

Steps
  • Traverse to /apps/settings/dam inside CRXDE lite.
  • Create a node of type cq:Page and name it 'cfm'
  • Under the newly created cfm node, create another node of type cq:Page and name it 'templates'.
  • Under templates node create a node of type cq:PageContent and name it 'jcr:content'.
  • Under jcr:content create a new boolean property called 'mergeList' with value 'true', this step ensures our new template is available in addition to /lib content fragment templates for authoring.
  • Now do 'Save All'.
Our crx looks like this now

Custom Content Fragment creation



We have the structure ready now, we will add properties for the template now by referring the /lib/ 'Simple Fragment' template.

  • Traverse to /libs/settings/dam/cfm/templates and copy 'simple' node.
  • Paste it on our structure under /apps/settings/dam/cfm/templates.
  • Now do a 'Save All'.

We now have below structure in crx.




We have a template similar to 'Simple Fragment' now. Let us customize the template for our need.

We will create title, description as elements and 2 variations for desktop and mobile.

Let us start by renaming 'simple' node to 'custom'

  • Select “jcr:content” under 'custom', Update the value of 'jcr:description' to 'A custom project specific fragment'.
  • Update value of 'jcr:title' to 'Custom Fragment'
  • Now rename 'main' under elements to 'title', update its 'jcr:title' to 'Title' and name to 'title'
  • Next create a new element – description by copying the  main and renaming. Update the 'jcr:title' to 'Description' and name to 'description'.
  • Now select node 'jcr:content' under node 'custom' and create a new node of type 'nt:unstructured' and name it 'variations'.
  • Create a new node for 'desktop' of type nt:unstructured under variations; add properties 'jcr:title' 'Desktop' and name 'desktop'.
  • Create a new node for 'mobile' of type nt:unstructured under variations; add properties 'jcr:title' 'Mobile' and name 'mobile'.
  • Now click on 'Save All'.

A new custom template is created now, which is ready for authoring.


Authoring Custom Content Fragment

Now go to AEM Assets >Files , click on 'Create' from top right hand corner and select 'Content Fragment'.
Here you can see the 'Custom Fragment'


Custom Fragment AEM 6.4



Select the 'Custom Fragment' and click 'next'.

Enter the values for title, description and click 'Create' then click on 'Open'.

Here you can see that a new Content Fragment is available with 'title', 'description'.
Similarly we can see that variations for 'desktop' and mobile also available for authoring.

In my upcoming blog, I will give a walkthrough on using Content Fragment with Progressive Web Applications.

Please dont forget to subscribe the blog.

Read More:

https://aem-cq-tutorials.blogspot.com/2018/06/create-content-service-end-point-in-aem.html

https://aem-cq-tutorials.blogspot.com/2018/05/aem-64-content-fragment-output-as-json.html




5 comments: