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"
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Create a Sling Model
Read that service configuration in the Sling Model
Use sling model in HTL file to read domains
Hi,
Create a Sling Model
Read that service configuration in the Sling Model
Use sling model in HTL file to read domains
@arunpatidar hi , I am getting stuck while getting service config data to model file
for eg :
public ProductDetailsConfiguration productDetailsConfiguration = new ProductDetailsConfiguration();
but I am getting null for :
log.info("ProductDetailsComponent test example: {}",productDetailsConfiguration.getCssCds());//it's giving null value
is there any other configuration that needs to be done between cfg.json and configuration.java file ?
was able to resolve the issue thank you.
@Reference
public ProductDetailsConfiguration productDetailsConfiguration;
Define env key/Value in the cfg.json and define the values in cloud manager config console for every environment.
Views
Likes
Replies
Views
Likes
Replies