Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

sling:alias issue for getting currentNode from currentPage

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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

Jörg

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

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

Jörg