#Adobe Experience Manager

How to Create an Image Component in AEM?

Contents

Short Answer

To create an image component in AEM, you need to define a new component in the CRXDE Lite, create its dialog for image properties, and write the necessary HTL/Sightly and JavaScript code to render the image on a webpage.

Overview of Creating an Image Component

An image component in AEM allows content authors to easily add and manage images within the pages of an AEM site. This component typically includes functionality to select an image from the DAM (Digital Asset Management), define alt text for accessibility, and possibly some styling options.

Step-by-Step Creation of an Image Component

Step 1: Define the Component in CRXDE Lite

  1. Access CRXDE Lite: Log into AEM Author and navigate to CRXDE Lite through the Tools menu.
  2. Create a New Component: In the appropriate project folder (usually under /apps/{your_project_name}/components), right-click and create a new component.
  3. Set Basic Properties: Name your component (e.g., image) and set the jcr:title and componentGroup to categorize your component appropriately in the AEM authoring UI.

Step 2: Create the Dialog for Image Properties

  1. Add a Dialog Node: Inside your component folder, create a node called cq:dialog to define the authoring dialog for the component.
  2. Define the Dialog Structure: Add a content node of type cq:WidgetCollection and within that add a tab1 node of type cq:TabPanel.
  3. Add Image Field: In tab1, add a field for authors to select the image, typically using the pathfield or fileupload xtype, which allows authors to choose an asset from the DAM or upload a new one.

Step 3: Write HTL/Sightly Code

  1. Create the HTL File: In the component folder, create an HTML file (e.g., image.html) that will use HTL (HTML Template Language) to define the rendering logic for the image.
  2. Add HTL Logic: Inside the HTL file, write the necessary HTL to display the image. Use properties set via the dialog to render the image source, alt text, and other attributes.

Step 4: Add Styling and Behavior (Optional)

  1. Define CSS: If styling is required, create a CSS file and link it within the HTL file to style the image as needed.
  2. Add Client Libraries: For additional behavior (like lazy loading), create and include a client library that contains JavaScript.

Step 5: Test the Component

  1. Deploy the Component: Ensure that the code is saved and then build and deploy your project or package to make the component available.
  2. Test in Authoring Mode: Open a page in the AEM authoring UI, add the new image component to the page, and test its functionality.
  3. Verify on the Published Page: Publish the page and verify that the image component looks and behaves as expected in the published site.

Best Practices for Image Components

  • Use AEM Core Components: Whenever possible, extend from the AEM Core Components, which provide a well-tested and versatile foundation for custom components.
  • Accessibility: Make sure to include an option for alt text to meet accessibility standards.
  • Responsive Design: Consider adding responsive properties to the component to ensure images look good on all devices.
  • Performance: Implement features like lazy loading to improve page load times.

Common Pitfalls to Avoid

  • Overcomplication: Avoid adding unnecessary features that clutter the authoring experience.
  • Hardcoding Paths: Use dialog properties and AEM’s DAM to manage image paths instead of hardcoding them.
  • Ignoring Caching: Make sure that the way images are served is compatible with AEM’s caching mechanisms.

Conclusion

Creating an image component in AEM involves setting up the component structure, defining its dialog, and implementing the rendering logic. By following these steps and adhering to AEM best practices, you can provide content authors with a flexible and easy-to-use tool to manage images on their sites. Remember to test thoroughly and consider performance and accessibility for the best user experience.

Back to Glossary

Axamit blog

Get Inside Scoop on Adobe Experience Manager Updates, Trends, Best Practices
October 18, 2024

Data Governance Framework: A Path to Data Integrity and Compliance

Explore how a data governance framework helps organizations manage data quality, security, and compliance with real-world examples and best practices.

Read More
October 2, 2024

How to Implement Data Governance: the Surefire Practices

Discover how proper data governance not only protects your business from risks but also empowers your team to unlock new opportunities and insights.

Read More
September 6, 2024

Optimizing Adobe Experience Manager Performance: Expert Techniques for Peak Results

Discover actionable techniques to boost Adobe Experience Manager performance and ensure a seamless experience for your users.

Read More