I have a Resource that represents a page. What is the proper way to get the URL for this page? These resources are coming from search Hit objects.
// in my case, paths are coming from search Hit objects
Resource pageResource = resourceResolver.getResource(path);
Page page = pageResource.adaptTo(Page.class);
String url = ...?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @dylanmccurry ,
Try the below code snippet might help. Here I am getting Resource and ResourceResolver from request.
PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);
Page currentPage = pageManager.getContainingPage(request.getResource());
String pagePath = currentPage.getPath();
Regards,
Santosh
Hi @dylanmccurry ,
Try the below code snippet might help. Here I am getting Resource and ResourceResolver from request.
PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);
Page currentPage = pageManager.getContainingPage(request.getResource());
String pagePath = currentPage.getPath();
Regards,
Santosh
HI @dylanmccurry
You can use below lines of code:
Resource pageResource = resourceResolver.getResource(path); String pagePath = pageResource.getPath.replace("/jcr:content", StringUtils.EMPTY);
Hope this helps!
Views
Likes
Replies