HTL Request Attributes with sly-include and sly-resource
With data-sly-include and data-sly-resource you can pass requestAttributes, which the receiving HTL script can then read and process.
<sly data-sly-use.settings="com.adobe.examples.htl.core.hashmap.Settings"
data-sly-include="${ 'productdetails.html' @ requestAttributes=settings.settings}" />
The requestAttributes map can come from a Java class:
public class Settings extends WCMUsePojo {
// passed as requestAttributes to data-sly-include / data-sly-resource
public Map<String, Object> settings = new HashMap<String, Object>();
@Override
public void activate() throws Exception {
settings.put("order", "ascending");
}
}
Reading request attributes in a Sling Model
@Model(adaptables=SlingHttpServletRequest.class)
public class ProductSettings {
@Inject @Optional @Default(values="empty")
public String order;
}
Here order is injected from the map set by the Use class.