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
<div data-sly-use.model3="${'com.bhf.aem.sling.models.Test' @ colour='red'}">
</div>
But I want to call a method in sling model twice with two different parameters .Is it possible with sling models?
Any Help!!!
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:
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:
By design of the HTL/Sightly language, sending parameters is only possible for
data-sly-use
(use objects initialization) anddata-sly-call
(template calls). The reason for this is to separate business logic from the view.As mentioned by @tomasz-szymulewski, since https://issues.apache.org/jira/browse/SLING-5812, there is support for passing request attributes on resource/script inclusion in the Sling/AEM implementation.