In a page level component I have set a variable.
<c:set var="stepIndex" value="-1" scope="page"/>
Now I author a few component on the page. These components should have access to the stepIndex variable. The components are written in HTL and I want to access stepIndex inside data-sly-use Javascript api.
How can I achieve this ?
I can do this using JSP scriplets using request. GET and SET attributes but I want to avoid that.
The page context is a JSP-specific implementation and HTL cannot access it. In order to share data between different servlets/scripting engines you should use the request scope. You can set the value with <c:set var="stepIndex" value="-1" scope="request"/>
and then retrieve it with request.getAttribute("stepIndex")