override Context-Aware Configuration (CAConfig) values at the page level | Community
Skip to main content
Level 2
June 13, 2025
Solved

override Context-Aware Configuration (CAConfig) values at the page level

  • June 13, 2025
  • 3 replies
  • 440 views

We are using CAConfig for injecting SEO metadata. It works great at the brand root (/content/brand-x) level. However, we have a requirement where authors should be able to override a few config values like og:title or og:image on a specific page, while still inheriting the rest from the brand-level configuration.

What is the best approach to override only some values at the page level using CAConfig?

Best answer by arunpatidar

Hi @nehaba4 

You can rely on Page Properties to override SEO values. Check if values from page properties exists then use those otherwise use CA config values.

3 replies

SantoshSai
Community Advisor
Community Advisor
June 13, 2025

Hi @nehaba4,

To override CAConfig values at the page level while still falling back to parent-level defaults, follow this hybrid approach:

Step 1: Enable CAConfig at Page Level

Ensure your page components or templates allow CAConfig to resolve from the page itself by using:

config = contextAwareConfig.resource().adaptTo(YourSEOConfig.class);

AEM will automatically walk up the content hierarchy (/content/page-x, /content/brand-x, etc.) until it finds a config node.

Step 2: Use Overlaying via /jcr:content/.config

You can override config at the page level by allowing authors to define a hidden configuration node:

/content/brand-x/page-x/jcr:content/.config/com.yourproject.config.SEOConfig

Populate only the properties you want to override - eg. just og:title.

Step 3: Use a Wrapper Sling Model to Merge Configs

Create a wrapper model that merges page-level and brand-level configs:

@Model(adaptables = Resource.class)
public class MergedSEOConfig {

    @Inject @Via("resource")
    @Optional
    private SEOConfig currentPageConfig;

    @Inject
    @Via("resource")
    @DefaultInjectionStrategy(OPTIONAL)
    private ConfigurationBuilder configBuilder;

    public String getOgTitle() {
        if (currentPageConfig != null && StringUtils.isNotBlank(currentPageConfig.ogTitle())) {
            return currentPageConfig.ogTitle();
        }
        return configBuilder.name("com.yourproject.config.SEOConfig").as(SEOConfig.class).ogTitle();
    }

    // Add other fields similarly...
}
Santosh Sai
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
June 13, 2025

Hi @nehaba4 

You can rely on Page Properties to override SEO values. Check if values from page properties exists then use those otherwise use CA config values.

Arun Patidar
kautuk_sahni
Community Manager
Community Manager
June 23, 2025

@nehaba4 Did you find the suggestions helpful? If you need more information, please let us know. If a response resolved your issue, kindly mark it as correct to help others in the future. Alternatively, if you discovered a solution on your own, we'd appreciate it if you could share it with the community. Thank you.

Kautuk Sahni