Hi Guys
I have one requirement where i need to get a current page path to pass it into some logic in component level and that component is used in experience fragment and that fragment is used in template, template used for creating pages.
Method 1-
<header data-sly-use.header="${'com.xyz.aem.core.models.Header' @ currentPagePath = currentPage.path}"
@RequestAttribute(name="currentPagePath")
private String currentPagePath;
Method 2-
@inject
private Page currentPage;
private String currentPagePath = currentPage.getPath();
I have used these two methods in sling model, its working as expected in local instance(author/publisher) and cloud author instance but in cloud publisher environment its giving the template path. if i use the component alone in a page its working fine but the requirement is to keep that component in experience fragment and SDI used to include that experience fragment in template level
Steps i followed to troubleshoot.
1-cleared the SDI level cache
2-cleared the page level cache
3-used loggers to check how its behaving
im not able to identify why its behaving,
Solved! Go to Solution.
Views
Replies
Total Likes
In your SlingModel use below code to get actual page path and page resource.
String pagePath = request.getPathInfo().replace(".html", "");
Resource pageResource = resourceResolver.getResource(pagePath);
@Abhishek16 you can try the below:
currentPage = request.getResourceResolver().adaptTo(PageManager.class).getContainingPage(resource);
Thanks for the response.
i used this method but getting experience fragment path, i might be using it wrong can you provide the full code if possible?
In your SlingModel use below code to get actual page path and page resource.
String pagePath = request.getPathInfo().replace(".html", "");
Resource pageResource = resourceResolver.getResource(pagePath);
Views
Likes
Replies
Views
Likes
Replies