AEM 6.4 has reached the end of extended support and this documentation is no longer updated. For further details, see our technical support periods. Find the supported versions here.
Some Content Fragment functionality requires the application of AEM 6.4 Service Pack 2 (6.4.2.0).
A content fragment extends a standard asset; see:
Creating and Managing Content Fragments and Page Authoring with Content Fragments for further information about content fragments.
Managing Assets and Customizing and Extending Assets for further information about standard assets.
The basic constituent parts of a content fragment are:
Depending on the type of fragment, either models or templates are also used:
Content fragment models are now recommended for creating all your fragments.
Content fragment models are used for all examples in We.Retail.
Content Fragment Models:
Any changes to an existing content fragment model can impact dependent fragments; this can lead to orphan properties in those fragments.
Content Fragment Templates:
Content Fragment Management (CFM) is part of AEM Assets as:
Content fragments with structured content (i.e. based on a content fragment model) are mapped to a single asset:
All content is stored under the jcr:content/data
node of the asset:
The element data is stored under the master sub-node:
jcr:content/data/master
Variations are stored under a sub-node that carries the name of the variation:
e.g. jcr:content/data/myvariation
The data of each element is stored in the respective sub-node as a property with the element name:
e.g. the content of element text
is stored as property text
on jcr:content/data/master
Metadata and associated content is stored below jcr:content/metadata
Except for the title and description, which are not considered traditional metadata and stored on jcr:content
Simple content fragments (based on a template) are mapped to a composite consisting of a main asset and (optional) sub-assets:
All non-content information of a fragment (such as title, description, metadata, structure) is managed on the main asset exclusively.
The content of the first element of a fragment is mapped to the original rendition of the main asset.
Additional elements (if existing) are mapped to sub-assets of the main asset.
As with standard assets, a content fragment is held under:
/content/dam
For further details see Content Fragment - Delete Considerations.
The Content Fragment Core Component is now recommended. See Developing Core Components for more details.
Content fragments can be referenced from AEM pages, just as any other asset type. AEM provides the Content Fragment core component - a component that allows you to include content fragments on your pages. You can also extend, this Content Fragment core component.
The component uses the fragmentPath
property to reference the actual content fragment. The fragmentPath
property is handled in the same manner as similar properties of other asset types; for example, when the content fragment is moved to another location.
The component allows you to select the variation to be displayed.
Additionally, a range of paragraphs can be selected to restrict the output; for example, this can be used for multi-column output.
The component allows in-between content:
For in-between content you need to:
Content Fragment Model:
When using a content fragment that has been based on a content fragment model on a page, the model is referenced. This means that if the model has not been published at the time you publish the page, this will be flagged and the model added to the resources to be published with the page.
Content Fragment Template:
When using a content fragment that has been based on a content fragment template on a page, there is no reference as the template was copied when creating the fragment.
The backend implementation of content fragments is, for example, responsible for making instances of a fragment used on a page searchable, or for managing mixed media content. This implementation needs to know which components are used for rendering fragments and how the rendering is parameterized.
The parameters for this can be configured in the Web Console, for the OSGi bundle DAM Content Fragments Configuration.
Resource types
A list of sling:resourceTypes
can be provided to define components that are used for rendering content fragments and where the background processing should be applied to.
Reference Properties
A list of properties can be configured to specify where the reference to the fragment is stored for the respective component.
There is no direct mapping between property and component type.
AEM simply takes the first property that can be found on a paragraph. So you should choose the properties carefully.
There are still some guidelines you must follow to ensure your component is compatible with the content fragment background processing:
The name of the property where the element(s) to be rendered is defined must be either element
or elementNames
.
The name of the property where the variation to be rendered is defined must be either variation
or variationName
.
If the output of multiple elements is supported (by using elementNames
to specify multiple elements), the actual display mode is defined by property displayMode
:
singleText
(and there is only one element configured) then the element is rendered as a text with in-between content, layout support, etc. This is the default for fragments where only one single element is rendered.If the fragment is rendered for displayMode
== singleText
(implicitly or explicitly) the following additional properties come into play:
paragraphScope
defines whether all paragraphs, or only a range of paragraphs, should be rendered (values: all
vs. range
)paragraphScope
== range
then the property paragraphRange
defines the range of paragraphs to be renderedContent fragments can be integrated with:
Translations
Content Fragments are fully integrated with the AEM translation workflow. On an architectural level, this means:
The individual translations of a content fragment are actually separate fragments; for example:
they are located under different language roots:
/content/dam/<path>/en/<to>/<fragment>
vs.
/content/dam/<path>/de/<to>/<fragment>
but they share exactly the same relative path below the language root:
/content/dam/<path>/en/<to>/<fragment>
vs.
/content/dam/<path>/de/<to>/<fragment>
Besides the rule-based paths, there is no further connection between the different language versions of a content fragment; they are handled as two separate fragments, although the UI provides the means to navigate between the language variants.
The AEM translation workflow works with /content
:
/conf
, these are not included in such translations. You can internationalize the UI strings.Metadata schemas
CFM provides its own, specific schema:
/libs/dam/content/schemaeditors/forms/contentfragment
this can be extended if required.
The respective schema form is integrated with the fragment editor.
You can use the server-side API to access your content fragments; see:
com.adobe.cq.dam.cfm
It is strongly recommended to use the server-side API instead of directly accessing the content structure.
The following three interfaces can serve as entry points:
Fragment Template
FragmentTemplate
Use FragmentTemplate.createFragment()
for creating a new fragment.
Resource templateOrModelRsc = resourceResolver.getResource("...");
FragmentTemplate tpl = templateOrModelRsc.adaptTo(FragmentTemplate.class);
ContentFragment newFragment = tpl.createFragment(parentRsc, "A fragment name", "A fragment description.");
This interface represents:
This information can include:
Access basic data (title, description)
Access templates/models for the elements of the fragment:
ElementTemplate
)Access templates for the variations of the fragment:
VariationTemplate
)Get initial associated content
Interfaces that represent important information:
ElementTemplate
VariationTemplate
Content Fragment
ContentFragment
This interface allows you to work with a content fragment in an abstract way.
It is strongly recommended to access a fragment through this interface. Changing the content structure directly should be avoided.
The interface provides you with the means to:
Manage basic data (e.g. get name; get/set title/description)
Access meta data
Access elements:
ContentElement
)List variations defined for the fragment
Create new variations globally
Manage associated content:
Access the fragment’s model or template
Interfaces that represent the prime elements of a fragment are:
Content Element
ContentElement
Get basic data (name, title, description)
Get/Set content
Access variations of an element:
Shortcut for resolving variations (applying some additional, implementation-specific fallback logic if the specified variation is not available for an element)
Content Variation
ContentVariation
All three interfaces ( ContentFragment
, ContentElement
, ContentVariation
) extend the Versionable
interface, which adds versioning capabilities, required for content fragments:
The following can be adapted:
ContentFragment
can be adapted to:
Resource
- the underlying Sling resource; note that updating the underlying Resource
directly, requires rebuilding the ContentFragment
object.Asset
- the DAM Asset
abstraction that represents the content fragment; note that updating the Asset
directly, requires rebuilding the ContentFragment
object.ContentElement
can be adapted to:
ElementTemplate
- for accessing the element’s structural information.FragmentTemplate
can be adapted to:
Resource
- the Resource
determining the referenced model or the original template that was copied;
Resource
are not automatically reflected in the FragmentTemplate
.Resource
can be adapted to:
ContentFragment
FragmentTemplate
It should be noted that:
The API is implemented to provide functionality supported by the UI.
The entire API is designed to not persist changes automatically (unless otherwise noted in the API JavaDoc). So you will always have to commit the resource resolver of the respective request (or the resolver you are actually using).
Tasks that might require additional effort:
ContentElement
will not update the data structure (but creating them globally from ContentFragment
will).For AEM 6.4 the client-side API is internal.
See the following:
filter.xml
The filter.xml
for content fragment management is configured so that it does not overlap with the Assets core content package.
An editing session is started when the user opens a content fragment in one of the editor pages. The editing session is finished when the user leaves the editor by selecting either Save or Cancel.
Requirements for controlling an editing session are:
The processes involved are:
Starting a session
Finishing a session
Auto save is stopped.
Upon commit:
Upon rollback:
Editing
The possible actions are:
Entering a page
Check if an editing session is already present; by checking the respective cookie.
If one exists, verify that the editing session was started for the content fragment that is currently being edited
If no edit session exists, wait for the first change made by the user (see below).
Check if the content fragment is already referenced on a page and display appropriate information if so.
Content change
Leaving a page
To achieve this you can adapt the resource that represents the API to:
com.adobe.cq.dam.cfm.ContentFragment
For example:
// first, get the resource
Resource fragmentResource = resourceResolver.getResource("/content/dam/fragments/my-fragment");
// then adapt it
if (fragmentResource != null) {
ContentFragment fragment = fragmentResource.adaptTo(ContentFragment.class);
// the resource is now accessible through the API
}
To create a new content fragment programmatically, you need to use:
com.adobe.cq.dam.cfm.ContentFragmentManager#create
For example:
Resource templateOrModelRsc = resourceResolver.getResource("...");
FragmentTemplate tpl = templateOrModelRsc.adaptTo(FragmentTemplate.class);
ContentFragment newFragment = tpl.createFragment(parentRsc, "A fragment name", "A fragment description.");
The auto save interval (measured in seconds) can be defined using the configuration manager (ConfMgr):
Node: <conf-root>/settings/dam/cfm/jcr:content
Property Name: autoSaveInterval
Type: Long
Default: 600
(10 minutes); this is defined on /libs/settings/dam/cfm/jcr:content
If you want to set an auto save interval of 5 minutes you need to define the property on your node; for example:
Node: /conf/global/settings/dam/cfm/jcr:content
Property Name: autoSaveInterval
Type: Long
Value: 300
(5 minutes equates to 300 seconds)
See Content Fragment Templates for full information.
For further information see