Context-Aware Configurations (Context Aware Configs) in Adobe Experience Manager (AEM) provide a way to manage configurations for an AEM application in a flexible and context-aware manner. They allow developers to define and manage configuration settings that can vary depending on different countries or regions. Here’s a more detailed explanation of Context Aware Configs in AEM:
- Dynamic Configurations: Context Aware Configs enable developers to define configuration settings that can change based on different contexts. These contexts can include various criteria such as the current user, device type, page, or any other context relevant to the application. This dynamic nature is especially useful for providing personalized experiences in AEM.
- Hierarchical Configuration: CA-Config follows a hierarchy-based approach within the repository. When searching for a configuration value, it begins at the specified configuration location. If the value isn’t found there, CA-Config checks higher levels in the hierarchy towards the root. This process continues until a matching configuration is discovered or the root node is reached. When the root node is reached without finding a specific configuration, a default value for that configuration should be applied.
- OSGi Configuration Support: Context Aware Configs integrate with OSGi (Open Service Gateway Initiative), which is a framework for managing modular applications in Java. This allows configurations to be exposed as OSGi services, making it easy to use them in AEM applications.
Allow me to illustrate the Context-Aware Configuration setup in AEM using an example. Imagine that we need to send “contact us” emails to different administrators depending on the country. In this scenario, I would create a context-aware configuration at the country level within the hierarchy and set distinct email addresses. These settings would be inherited by all the relevant pages. If necessary, I can also override these configurations at lower levels in the hierarchy to specify different email addresses.
Setup Required for Context Aware Config
Before setup its important for me to introduce the WCM.io which provides a content package that enables you to edit Context-Aware Configurations (CAC) through the authoring UI in Adobe Experience Manager (AEM). This content package simplifies the process of managing context-aware configurations by integrating with AEM’s Web Content Management (WCM) system
1) Firstly add wcmio dependencies to main pom
2) Include wcmio packages as embed packages in all pom to deploy to AEM.
3) Create configuration page template : Add a static template which uses “wcm-io/caconfig/editor/components/page/editor” as resourceType.
Create CA config
1) Add the caconfig class with the required props
2) Core pom – Include your class in bnd-maven-plugin
Incorporate your Context-Aware configuration settings into your backend code, which includes OSGi services, Sling Models, and associated components. You can achieve this integration by utilising the ConfigurationBindingsValueProvider.
You can enable HTL access to these values through two simple methods.
First, you can fetch them within a Sling Model and provide access through getter methods. This allows components to include the Sling Model in HTL and readily access the required values.
Alternatively, you can utilize the ConfigurationBindingsValueProvider to achieve the same outcome.
Authoring Context Aware Config
Now you can go ahead configure the Context Aware Config on a configuration page created from the static template
This Context Aware Config will get saved to the path of the cq:conf(value=/conf/myproject/us) property, set on the context path /content/myproject/us.
To validate this configuration, you can use a handy tool in the OSGi web console. Navigate to http://localhost:4502/system/console/slingcaconfig