Hi All,
I have created sling model for multifield which accept page path and from that page path need to access to page property That part i have done and it working fine.
issue is I wanted to access parent page title from the page path.
do you know how to do it?
please check the below code to access page property from the page path
String pagePath = pagePathResource.adaptTo(ValueMap.class).get("pagePath", String.class);
BlogPostModal blogPostModal = resourceResolver.getResource(pagePath + "/jcr:content")
.adaptTo(BlogPostModal.class);
blogPostModal.setResourcePath(pagePath != null ? pagePath : "");
blogPageList.add(blogPostModal);
Solved! Go to Solution.
Views
Replies
Total Likes
You can try below:
1. get the resource of the page path
2. Adapt To Page Object - Here you can get all the info about the current page
3. Get Parent page using page.getParent()
Note: If you just want page title, you can get it from page object otherwise you can even get using valuemap.
Resource res = resolver.getResource(pagePath);
Page page= res.adaptTo(Page.class);
String pageTitle = page.getPageTitle();
Page parentPage = page.getParent();
String parentPageTitle = parentPage.getPageTitle();
Hope this helps you.
Hi @savi50,
You can use Page api to achieve your goal:
import com.day.cq.wcm.api.Page; // place for other code // getting parent page properties for given page base on page path resourceResolver.getResource(pagePath).adaptTo(Page.class).getParent().getProperties();
Of course it will be good to add some null check to above code.
You can also get title using getPageTitle or getTitle() methods, like this:
import com.day.cq.wcm.api.Page; // place for other code // getting parent page properties for given page base on page path resourceResolver.getResource(pagePath).adaptTo(Page.class).getParent().getPageTitle(); // or resourceResolver.getResource(pagePath).adaptTo(Page.class).getParent().getTitle();
You can try below:
1. get the resource of the page path
2. Adapt To Page Object - Here you can get all the info about the current page
3. Get Parent page using page.getParent()
Note: If you just want page title, you can get it from page object otherwise you can even get using valuemap.
Resource res = resolver.getResource(pagePath);
Page page= res.adaptTo(Page.class);
String pageTitle = page.getPageTitle();
Page parentPage = page.getParent();
String parentPageTitle = parentPage.getPageTitle();
Hope this helps you.