I am having a scenario in which i want to call a sling model with input parameter. For this i have a code like this
From AEM 6.3 there is a new HTL feature that allows to do this.
In the data-sly-include and data-sly-resource you can now pass requestAttributes in order to use them in the receiving HTL-script. This allows you to properly pass-in parameters into scripts or components.
Java-code of the Settings class, the Map is used to pass in the requestAttributes:
public class Settings extends WCMUsePojo {
// used to pass is requestAttributes to data-sly-resource
public Map settings = new HashMap();
@Override
public void activate() throws Exception {
settings.put("layout", "flex");
}
}
For example, via a Sling-Model, you can consume the value of the specified requestAttributes. In this example, layout is injected via the Map from the Use-class:
@Model(adaptables=SlingHttpServletRequest.class)
public class ProductSettings {
@Inject @Optional @Default(values="empty")
public String layout;
}