sling:alias issue for getting currentNode from currentPage | Community
Skip to main content
Jaggu_Accenture
Level 2
September 17, 2018
Solved

sling:alias issue for getting currentNode from currentPage

  • September 17, 2018
  • 1 reply
  • 926 views

Hi Team,

Can somebody send me the code or api , if I will pass current page url (which contains alias name) then it will return the exact content path. Means I want read the current page jcr:content properties but its returning null because in currentpage is mixed with sling:alias.

Example:

Without alias: http://localhost:4502/content/aaabbccc/test.html

With alias:  http://localhost:4502/content/abc/test.html

My code:

String currentPage=slingHttpServletRequest.getPathInfo();

if (currentPage.contains(".html")) {

currentPage = currentPage.replace(".html", "");

}

Node currentNode = resourceResolver.getResource(currentPage).adaptTo(Node.class);

the above code is returning null because currentPage path is "/content/abc/test" and there is no resource like "/content/abc/test" because of  "abc" is alias "/content/aaabbccc/test" .

If I will access " http://localhost:4502/content/aaabbccc/test.html" then result is coming fine.

Regards,

Jaganath

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 joerghoh

Node currentNode = request.getResource().adaptTo(Node.class);

Jörg

1 reply

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
September 17, 2018

Node currentNode = request.getResource().adaptTo(Node.class);

Jörg