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.
<sly data-sly-use.settings="com.adobe.examples.htl.core.hashmap.Settings"
data-sly-include="${ 'productdetails.html' @ requestAttributes=settings.settings}"/>
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<String, Object> settings = new HashMap<String, Object>();
@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;
}