A basic building block of any digital experience, the cheer.IOs Image Component enables the author to add an image from the DAM with added options for including a caption or photo credit.
Component Information
Component Title
Image
Description
Allows easy placement of image assets and offers in-place editing such as cropping. Alt-text, attribution links and captions can be added as well
Features
Smart loading of optimal rendition
In-place editing, cropping, rotating, resizing and image map definition
Responsive image map resizing
Image title, description, accessibility text and link
The Image component uses the com.adobe.cq.wcm.core.components.models.Image Sling Model as its Use-object.
Client Libraries
The component provides a core.wcm.components.image.v2 client library category that contains a recommended base CSS styling and JavaScript component. It should be added to a relevant site client library using the embed property.
It also provides a core.wcm.components.image.v2.editor editor client library category that includes JavaScript handling for dialog interaction. It is already included by its edit dialog.
BEM Description
BLOCK cmp-image
ELEMENT cmp-image__link
ELEMENT cmp-image__image
ELEMENT cmp-image__title
JavaScript Data Attribute Bindings
Apply a data-cmp-is="image" attribute to the wrapper block to enable initialization of the JavaScript component.
The following attributes can be added to the same element to provide options:
data-cmp-lazy - if not false, indicates that the image should be rendered lazily.
data-cmp-src - the image source. Can be a simple image source, or a URI template representation that can be variable expanded - useful for building an image configuration with an alternative width. Should contain a {.width} variable. e.g. '/path/to/image.coreimg{.width}.jpeg'
data-cmp-widths - a comma-separated string of alternative image widths (in pixels). Populated with allowedRenditionWidths from the component's edit dialog.
A hook attribute from the following should be added to the corresponding element so that the JavaScript is able to target it:
The img and an optional image map should be placed inside a noscript element with the data-cmp-hook-image="noscript" attribute. They will be inserted into the DOM by the JavaScript component.
To allow lazy loading it is expected that the data-cmp-lazy and data-cmp-src options are supplied.
It is possible to configure the JavaScript component such that the most appropriate image url is built and applied to the img. The most appropriate width being the one which is at least as wide as the image's container. The data-cmp-widths option must be provided with more than one width, as well as the data-cmp-src option, with a URI template representation of the source.
To allow responsive recalculation of image map areas, a data-cmp-relcoords attribute should be added to each map area. The coordinates are represented as comma-separated decimal percentages:
SVG MIME-types are supported, but have some specific handling. Alternative smart image widths defined at the component policy dialog are ignored for SVG images, with Image#getWidths returning an empty array. In addition, SVG image types have a more limited set of editing options available in the AEM inline image editor. The lazy loading feature is still supported for SVG images.
Extending the Components
Extending the components can be done in multiple ways depending on the needs of the brand component.
Use this approach if you do not have any required html markup changes or backend java changes. This will only update the title of the component, componentGroup and point to the resourceSuperType. Optionally can extend the description.
Change .content.xml file properties
sling:resourceSuperType to point to the Cheer.IOs component [required]
jcr:title - new Component title
componentGroup - Brand specific Group [required]
jcr:description - Helpful description
Use this approach if you need to update css classes or add data attributes and do not need to change the backend model, or potentially want to use a different model by retain all of the markup in the component-tmpl.html (Component Template) markup.
Follow steps in Extend the Component - Basic
Extend the file i.e. extend-example-option2.html
Update file with new properties
Update the html file with desired changes
The component template is usually named component-tmpl.html this file contains the html markup. Update this file if you need to change the html structure of the component.
Follow Steps in Extend Component Basic
Extend the file component.html to point to the new component-tmpl.html file
Extend the file i.e. component-tmpl.html
Update file with new markup
Use this approach if you need to change the Sling Model to update the backend logic.
Files that will need to be added when extending:
Follow Steps in Extend Component - Basic
Java Interface - this will implement the model with the new methods (if needed)
Sling Model - this will implement the Java Interface from step 1 and leverage the sling delegation pattern to override the original methods
The component.html file to match the new component name
It is possible to extend more than just the component.html file, if necessary any file that is resourceSupertyped can be extend for example if something needs added to the dialog.
This gives us the flexibility to change our classes or add attributes easily. Say I want to add new javascript I can easily target a different data attribute to trigger my javascript.
Important Notes:
In case you overwrite the image's HTL script, make sure the necessary attributes for the JavaScript loading script are contained in the markup at the right position (see section below).
In case your own component does not only render an image but does also renders something else, use the following approach:
ResourceSuperType should be set to core/wcm/components/image/v1/image (to make sure the image rendering servlet is being used)
Your HTL script should include the image markup via <div class="cmp-image" data-sly-include="image.html"></div>
You derived component should reset cq:htmlTags
Your component's dialog should overwrite the dialog fully from the image component via sling:hideResource="true" on the node cq:dialog/content/items/image
URL Formats
The images are loaded through the com.adobe.cq.wcm.core.components.internal.servlets.AdaptiveImageServlet, therefore their URLs have the following patterns:
./allowedRenditionWidths - defines the allowed renditions (as an integer array) that will be generated for the images rendered by this component; the actual size will be requested by the client device;
./jpegQuality - defines the image quality for JPEGs (0 lowest quality / size to 100 highest quality / size). Default value is 82.
./disableLazyLoading - if true, the lazy loading of images (loading only when the image is visible on the client device) is disabled.
Note: The author should NOT be able to upload an image from their device. The assets MUST come from the DAM
Policy Configuration Visual
Edit Dialog Properties
The following properties are written to JCR for this Image component and are expected to be available as Resource properties:
./fileReference property or file child node - will store either a reference to the image file, or the image file
./decorative - if set to true, then the image will be ignored by assistive technology
./alt - defines the value of the HTML alt attribute (not needed if ./decorative is set to true)
./altValueFromDAM - if set to true, .image attribute with the value of the dc:description metadata in DAM (not needed if ./decorative is set to true)
./photoCaption - Photo Caption
./titleValueFromDAM - If set to true, populate the image's caption with the value of the dc:title metadata in DAM
./displayPopupTitle - if set to true it will render the value of the ./jcr:title property through the HTML title attribute, otherwise a caption will be rendered
./PhotoCredit - Used to display the photographer, illustrator, or copyright holder's information
./photoCreditValueFromDAM - if set to true, populate the image's photo credit value from metadata from DAM