sling:alias issue for getting currentNode from currentPage

Avatar

Avatar

Jaggu_Accenture

Avatar

Jaggu_Accenture

Jaggu_Accenture

17-09-2018

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

991

Correct Reply

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

991

Correct Reply

1.0K
Jörg_Hoh
Employee

17-09-2018

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

Jörg

Answers (0)