Unable to get current Page Path in cloud publisher environment. | Community
Skip to main content
Level 2
July 19, 2023
Solved

Unable to get current Page Path in cloud publisher environment.

  • July 19, 2023
  • 2 replies
  • 1523 views

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-

@586265 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,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anudeep_Garnepudi

@abhishek16 

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);

 

2 replies

Manu_Mathew_
Community Advisor
Community Advisor
July 19, 2023

@abhishek16 you can try the below:

currentPage = request.getResourceResolver().adaptTo(PageManager.class).getContainingPage(resource);
Level 2
July 20, 2023

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? 

 

 

Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
July 29, 2023

@abhishek16 

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);