Getting currentPage as the template page(/conf/projectname/settings/wcm/templates/templatename) and not the page I am browsing(/content/projectname/en/homePage)
I have created a custom container component which extends the core container component with following code in its overlayed HTL(this component is exactly the same as the one we get in AEM project archetype except this modified HTL):
<sly data-sly-use.customContainer="com.trainingProject.core.models.CustomContainer">
<sly data-sly-test.hasFragment="${customContainer.fragmentPresent}">${customContainer.htmlSrc @2941342='html'}</sly>
</sly>
<sly data-sly-test=${!hasFragment} data-sly-use.container="com.adobe.cq.wcm.core.components.models.LayoutContainer">
<sly data-sly-test.responsive="${container.layout == 'RESPONSIVE_GRID'}"
data-sly-use.responsiveGridTemplate="responsiveGrid.html"
data-sly-call="${responsiveGridTemplate.responsiveGrid @ container=container}"></sly>
<sly data-sly-test.simple="${!responsive}"
data-sly-use.simpleTemplate="simple.html"
data-sly-call="${simpleTemplate.simple @ container=container}"></sly>
</sly>
This Custom container component is authored on template structure of an editable template.
Whenever a component (say component X) is dragged-dropped inside this custom container, and we open the page created using this template on browser, the sling model of Component X gets currentPage (injected using @ScriptVariable private Page currentPage😉 as the template page and not the actual page we are browsing.
However, the same component X authored on the same template but outside of the custom container component gives the correct currentPage(the one we are browsing). It render all other components(eg text, accordion etc) fine which do not have a dependency on currentPage to render the data.
There seems to be something wrong with the custom container as the same component X works fine with the OOTB core container component.
I am not sure why are we not able to get the correct currentPage(the one we are browsing) using custom container.
Any help is appreciated
I am using AEM could service sdk and java 11
Thanks!