how to add inline config value to html file and java file from cfg.json file in AEM as a cloud service
hi, I want my variable which I have declared in cfg.json file to be used instead of static value in HTML file .please help me how to do it.
my cfg.json file is :
{
"cssCds": "https://www.example.css",
"jsCds":"https://www.example.js"
}I am made one configuration java file which is :
@Component(service = ProductDetailsConfiguration.class)
@Designate(ocd = ProductDetailsConfiguration.Configuration.class)
public class ProductDetailsConfiguration {
private String cssCds;
private String jsCds;
@ObjectClassDefinition(name = "configuration Service")
@interface Configuration {
@AttributeDefinition(name = "Css Cds", type = AttributeType.STRING, description = "URL for css file of CDS")
String cssCds() default "https://www.example.css";
@AttributeDefinition(name = "Js Cds", type = AttributeType.STRING, description = "URL for js file of CDS")
String jsCds() default "https://www.example.js";
}
@Activate
@Modified
protected void activate(final ProductDetailsConfiguration.Configuration cfg) {
this.cssCds = cfg.cssCds();
this.jsCds = cfg.jsCds();
}
public String getCssCds() {
return this.cssCds;
}
public String getJsCds() {
return this.jsCds;
}
}
I have one HTML file where I want to use these variables instead of hardcoded URLs
for e.g.:
<link href="https://www.example.css" rel="stylesheet" type="text/css">
// I want to replace "https://www.example.css" with the variable defined in cfg.json file that is "cssCds"
