When you start to develop new components you need to understand the basics of their structure and configuration.

This process involves reading the theory and looking at the wide range of component implementations in a standard AEM instance. This latter approach is slightly complicated by the fact that, at the moment, AEM caters for components for both the touch-optimized and classic UIs.

Overview

This section covers key concepts and issues as an introduction to the details needed when developing your own components.

Planning

Before starting to actually configure/code your component you should ask:

What exactly do you need the new component to do?

A clear specification helps at all stages of development, testing and handover.
Details may change over time, but the specification can be updated (though changes should be documented too).

Touch-Optimized vs Classic UI

Before any serious discussion starts about developing components you need to know which UI your authors will be using:

Touch-Optimized UINew(er) user interface that was introduced in 5.6.0 as a preview and extended in 6.0, 6.1 and 6.2. It is based on the unified user experience for the Adobe Marketing Cloud, using the underlying technologies of Coral UI and Granite UI.

Classic UI
User interface based on ExtJS technology that was introduced with CQ 5.1 in 2008.

Components can be implemented to support the touch-optimized UI, the classic UI or both. When looking at a standard instance you will also see out-of-the-box components that were originally designed for the classic UI, or the touch-optimized UI and/or both.

For this reason we will cover the basics of both, and how to recognize them, on this page.

Content Logic and Rendering Markup

It is recommended to keep the code responsible for markup and rendering separate from the code that controls the logic used to select the component's content.

This philosophy is supported by HTL, a templating language that is purposely limited to ensure a real programming language is used to define the underlying business logic. This (optional) logic is invoked from HTL with a specific command; this mechanism highlights the code that is called for a given view and, if required, allows specific logic for different views of the same component.

HTL vs JSP

HTL is a HTML templating language, introduced with AEM 6.0.

The discussion of whether to use HTL or JSP (Java Server Pages) when developing your own components should be straightforward as HTL is now the recommended scripting language for AEM.

Both HTL and JSP can be used for developing components for both the classic and the touch-optimized UI. Although there can be a tendency to assume that HTL is only for the touch-optimized UI and JSP for the classic UI, this is a misconception and more due to timing - the touch-optimized UI and HTL were incorporated into AEM over approximately the same period and as HTL is now the recommended language it is being used for new components, which tend to be for the touch-optimized UI.

Note:

The exceptions are Granite UI Foundation Form Fields (as used in dialogs). These still require the use of JSP.

Developing Your Own Components

To create your own components for the appropriate UI see (after reading this page):

Moving Components to the Publish Instance

The components that render content must be deployed on the same AEM instance as the content. Therefore, all components that are used for authoring and rendering pages on the author instance must be deployed on the publish instance. When deployed, the components are available to render activated pages.

Use the following tools to move your components to the publish instance:

AEM standard components are defined as cq:Component and have the key elements:

jcr properties:
A list of jcr properties; these are variable and some may be optional though the basic structure of a component node, its properties and subnodes are defined by the cq:Component definition

Resources:
These define static elements used by the component.

Scripts:
Are used to implement the behavior of the resulting instance of the component.

Root Node:

<mycomponent> (cq:Component) - Hierarchy node of the component.

Vital Properties:

jcr:title - Component title; for example, used as a label when the component is listed in the components browser or sidekick.

jcr:description - Description for the component; can be used as mouse-over hint in the components browser or sidekick.

Classic UI:

icon.png - Icon for this component.

thumbnail.png - Image shown if this component is listed within the paragraph system.

Vital Child Nodes:

cq:editConfig (cq:EditConfig) - Defines the edit properties of the component and enables the component to appear in the Components browser or Sidekick.
Note: if the component has a dialog, it will automatically appear in the Components browser or Sidekick, even if the cq:editConfig does not exist.

cq:childEditConfig (cq:EditConfig) - Controls author UI aspects for child components that do not define their own cq:editConfig.

Touch-optimized UI:

cq:dialog (nt:unstructured) - Dialog for this component in the touch-optimized UI. Defines the interface allowing the user to configure the component and/or edit content.

cq:design_dialog (nt:unstructured) - Design editing for this component in the touch-optimized UI.

Classic UI:

dialog (cq:Dialog) - Dialog for this component in the classic UI. Defines the interface allowing the user to configure the component and/or edit content.

design_dialog (cq:Dialog) - Design editing for this component in the classic UI.

Properties and Child Nodes of a Component

Many of the nodes/properties needed to define a component are common to both UIs, with differences remaining independent so that your component can work in both environments.

A component is a node of type cq:Component and has the following properties and child nodes:

Name

Type

Description

.

cq:Component

Current component. A component is of node type cq:Component.

componentGroup

String

Group under which the component can be selected in the Components browser (touch-optimized UI) or Sidekick (classic UI).
A value of .hidden is used for components that are not available for selection from the UI; such as the actual paragraph systems.

cq:isContainer

String

Indicates whether the component is a container component and therefore can contain other components; for example a paragraph system.

cq:dialog

nt:unstructured

Definition of the edit dialog for the touch-optimized UI.

dialog

cq:Dialog

Definition of the edit dialog for the classic UI.

cq:design_dialog

nt:unstructured

Definition of the design dialog for the touch-optimized UI.

design_dialog

cq:Dialog

Definition of the design dialog for the classic UI.

dialogPath

String

Path to a dialog; to cover the case when the component does not have a dialog node.

Returns additional tag attributes that are added to the surrounding html tag. Enables addition of attributes to the automatically generated divs.

cq:noDecoration

Boolean

If true, the component is not rendered with automatically generated div and css classes.

cq:template

nt:unstructured

If found, this node will be used as a content template when the component is added from the Components browser or Sidekick.

cq:templatePath

String

Path to a node to use as a content template when the component is added from the Components browser or Sidekick. This must be an absolute path, not relative to the component node.
Unless you want to reuse content already available elsewhere, this is not required and cq:template is sufficient (see below).

jcr:created

Date

Date of creation of the component.

jcr:description

String

Description of the component.

jcr:title

String

Title of the component.

sling:resourceSuperType

String

When set, the component inherits from this component.

virtual

sling:Folder

Enables creation of virtual components. To see an example, please look at the contact component at:/libs/foundation/components/profile/form/contact

<breadcrumb.jsp>

nt:file

Script file.

icon.png

nt:file

Icon of the component, appears next to the Title in Sidekick.

thumbnail.png

nt:file

Optional thumbnail that is shown while the component is dragged into place from Sidekick.

If we look at the Text component (either version), we can see these elements:

HTL (/libs/wcm/foundation/components/text)

JSP (/libs/foundation/components/text)

Properties of particular interest include:

jcr:title - title of the component; this can be used to identify the component, for example, it appears in the component list within the components browser or sidekick

jcr:description - description for the component; can be used as mouse-over hint in the component list within sidekick

sling:resourceSuperType: this indicates the path of inheritance when extending a component (by overriding a definition)

Child nodes of particular interest include:

cq:editConfig (cq:EditConfig) - this controls visual aspects; for example, it can define the appearance of a bar or widget, or can add customized controls

cq:childEditConfig (cq:EditConfig) - this controls the visual aspects for child components that do not have their own definitions

Touch-optimized UI:

cq:dialog (nt:unstructured) - defines the dialog for editing content of this component in the touch-optimized UI

cq:design_dialog (nt:unstructured) - specifies the design editing options for this component in the touch-optimized UI

Classic UI:

dialog (cq:Dialog) - defines the dialog for editing content of this component (specific to the classic UI)

design_dialog (cq:Dialog) - specifies the design editing options for this component in the classic UI

icon.png - graphics file to be used as an icon for the component in sidekick

thumbnail.png - graphics file to be used as a thumbnail for the component while dragging it from the sidekick

Dialogs

Dialogs are a key element of your component as they provide an interface for authors to configure and provide input to that component.

Depending on the complexity of the component your dialog may need one or more tabs - to keep the dialog short and to sort the input fields.

Dialog definitions are specific to the UI:

Note:

For compatibility purposes the touch-optimized UI can use the definition of a classic UI dialog, when no dialog has been defined for the touch-optimized UI.

The Dialog Conversion Tool is also provided to help you extend/convert components that only have dialogs defined for the classic UI.

Touch-Optimized UI

cq:dialog (nt:unstructured) nodes:

define the dialog for editing content of this component

specific to the touch-optimized UI

are defined using Granite UI components

have a property sling:resourceType, as standard Sling content structure

can have a property helpPath to define the context sensitive help resource (absolute or relative path) that is accessed when the Help icon (the ? icon) is selected; for out-of-the box components this often references a page in the documentation; if no helpPath is specified, the default URL (documentation overview page) is shown.

Within the dialog, individual fields are defined:

Classic UI

dialog (cq:Dialog) nodes

define the dialog for editing content of this component

specific to the classic UI

are defined using ExtJS widgets

have a property xtype, which refers to ExtJS

can have a property helpPath to define the context sensitive help resource (absolute or relative path) that is accessed when the Help button is selected; for out-of-the box components this often references a page in the documentation; if no helpPath is specified, the default URL (documentation overview page) is shown.

Within the dialog, individual fields are defined:

Within a classic dialog:

you can create the dialog as cq:Dialog, which will provide a single tab - as in the text component, or if you need multiple tabs, as with the textimage component, the dialog can be defined as cq:TabPanel.

a cq:WidgetCollection (items) is used to provide a base for either input fields (cq:Widget) or further tabs (cq:Widget). This hierarchy can be extended.

Design Dialogs

Design dialogs are very similar to the dialogs used to edit and configure content, but they provide the interface for authors to configure and provide design details for that component.

The design dialog for the paragraph system (e.g. parsys) is a special case as it allows the user to specific other components to be available for selection (from the components browser or sidekick) on the page.

Adding your Component to the Paragraph System

Once a component has been defined it must be made available for use. To make a component available for use in a paragraph system you can either:

within the content, this generates the property jcr:title holding the author's content.

The properties defined are dependent on the individual definitions. Although they can be more complex than above they still follow the same basic principles.

Component Hierarchy and Inheritance

Components within AEM are subject to 3 different hierarchies:

Resource Type Hierarchy
This is used to extend components using the property sling:resourceSuperType. This enables the component to inherit; for example a text component will inherit various attributes from the standard component.

scripts (resolved by Sling)

dialogs

descriptions (including thumbnail images, icons, etc)

Container Hierarchy
This is used to populate configuration settings to the child component and is most commonly used in a parsys scenario.
For example, configuration settings for the edit bar buttons, control set layout (editbars, rollover), dialog layout (inline, floating) can be defined on the parent component and propagated to the child components.
Configuration settings (related to edit functionality) in cq:editConfig and cq:childEditConfig are propagated.

Include Hierarchy
This is imposed at runtime by the sequence of includes.
This hierarchy is used by the Designer, which in turn acts as the base for various design aspects of the rendering; including layout information, css information, the available components in a parsys among others.

Edit Behavior

This section explains how to configure the edit behavior of a component. This includes attributes such as actions available for the component, characteristics of the inplace editor and the listeners related to events on the component.

The configuration is common to both the touch-optimized and classic UI, albeit with certain, specific differences.

The edit behavior of a component is configured by adding a cq:editConfig node of type cq:EditConfig below the component node (of type cq:Component) and by adding specific properties and child nodes. The following properties and child nodes are available:

cq:actions (String array): defines the actions that can be performed on the component.

cq:layout (String): : defines how the component is edited in the classic UI.

cq:dialogMode (String): defines how the component dialog is opened in the classic UI; in the touch-optimized UI, dialogs are always floating in desktop mode, and automatically opened as fullscreen in mobile.

cq:emptyText (String): defines text that is displayed when no visual content is present.

cq:inherit (Boolean): defines if missing values are inherited from the component that it inherits from.

cq:dropTargets (node type nt:unstructured): defines a list of drop targets that can accept a drop from an asset of the content finder (multiple drop targets are only available in the classic UI, in the touch-optimized UI a single drop target is allowed).

cq:actionConfigs (node type nt:unstructured): defines a list of new actions that are appended to the cq:actions list.

There are many existing configurations in the repository. You can easily search for specific properties or child nodes:

To look for a property of the cq:editConfig node, e.g. cq:actions, you can use the Query tool in CRXDE Lite and search with the following XPath query string://element(cq:editConfig, cq:EditConfig)[@cq:actions]

To look for a child node of cq:editConfig, e.g. you can search for cq:dropTargets, which is of type cq:DropTargetConfig; you can use the Query tool in CRXDE Lite and search with the following XPath query string://element(cq:dropTargets, cq:DropTargetConfig)

Configuring with cq:EditConfig Properties

cq:actions

The cq:actions property (String array) defines one or several actions that can be performed on the component. The following values are available for configuration:

Property Value

Description

text:<some text>

Displays the static text value <some text>
Only visible in classic UI. The touch-optimized UI does not display actions in a contextual menu, so this is not applicable.

-

Adds a spacer.
Only visible in classic UI. The touch-optimized UI does not display actions in a contextual menu, so this is not applicable.

edit

Adds a button to edit the component.

delete

Adds a button to delete the component

insert

Adds a button to insert a new component before the current one

copymove

Adds a button to copy and cut the component.

The following configuration adds an edit button, a spacer, a delete and an insert button to the component edit bar:

cq:emptyText

The cq:emptyText property (String) defines text that is displayed when no visual content is present. It defaults to: Drag components or assets here.

cq:inherit

The cq:inherit property (boolean) defines whether missing values are inherited from the component that it inherits from. It defaults to false.

Configuring with cq:EditConfig Child Nodes

cq:dropTargets

The cq:dropTargets node (node type nt:unstructured) defines a list of drop targets that can accept a drop from an asset dragged from the content finder. It serves as a collection of nodes of type cq:DropTargetConfig.

Note:

Multiple drop targets are only available in the classic UI.

In the touch-optimized UI only the first target will be used.

Each child node of type cq:DropTargetConfig defines a drop target in the component. The node name is important because it must be used in the JSP, as follows, to generate the CSS class name assigned to the DOM element that is the effective drop target:

<drop target css class> = <drag and drop prefix> +
<node name of the drop target in the edit configuration>

The <drag and drop prefix> is defined by the Java property:

com.day.cq.wcm.api.components.DropTarget.CSS_CLASS_PREFIX.

For example, the class name is defined as follows in the JSP of the Download component
(/libs/foundation/components/download/download.jsp), where file is the node name of the drop target in the edit configuration of the Download component:

String ddClassName = DropTarget.CSS_CLASS_PREFIX + "file";

The node of type cq:DropTargetConfig needs to have the following properties:

Property Name

Property Value

accept

Regex applied to the asset mime type to validate if dropping is allowed.

groups

Array of drop target groups. Each group must match the group type that is defined in the content finder extension and that is attached to the assets.

propertyName

Name of the property that will be updated after a valid drop.

The following configuration is taken from the Download component. It enables any asset (the mime-type can be any string) from the media group to be dropped from the content finder into the component. After the drop, the component property fileReference is being updated:

cq:actionConfigs

The cq:actionConfigs node (node type nt:unstructured) defines a list of new actions that are appended to the list defined by the cq:actions property. Each child node of cq:actionConfigsdefines a new action by defining a widget.

The following sample configuration defines a new button (with a separator for the classic UI):

a separator, defined by the xtype tbseparator;

This is only used by the classic UI.

This definition is ignored by the touch-optimized UI as xtypes are ignored (and separators are unnecessary as the action toolbar is constructed differently in the touch-optimized UI).

a button named Manage comments that runs the handler function CQ_collab_forum_openCollabAdmin().

For the classic UI, to see which parameters can be used in the handlers, refer to the before<action> and after<action> events section of the CQ.wcm.EditBar and CQ.wcm.EditRollover widget documentation.

With the following configuration the page is refreshed after the component has been deleted, edited, inserted or moved: