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?
Solved! Go to Solution.
Hi @NehaBa4,
To override CAConfig values at the page level while still falling back to parent-level defaults, follow this hybrid approach:
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.
/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
.
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...
}
@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.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies