Expand my Community achievements bar.

Get ready! An upgraded Experience League Community experience is coming in January.
SOLVED

Trying to get the different page title in my sling model

Avatar

Level 9
Hello Team,
 
I have a page which has these title
jcr:title has the value: ABC Page
navTitle has the value: navTitle123
pageTitle has the value: myPageTitle
 
In my custom sling model logic, I have written these statements to get the page title.

 

 

 

 

private Page currentPage; // Initialized properly with annotation.
 
String navTitle = StringUtils.defaultIfEmpty(currentPage.getNavigationTitle(), currentPage.getTitle());
// Displays Navigation title: navTitle123
 
String newTitle = currentPage.getTitle();
// This displays "ABC Page" instead of "myPageTitle"
 
 

 

 

 

When I googled, i came to know that currentPage.getTitle() internally checks for page Title. If its not present, then only it returns jcr:title
 
Mahesh_Gunaje_0-1741089290588.png

 

 
So, What I am missing here?
 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Mahesh_Gunaje,

I do not thing that there is any fallback. According to official documentation:


Returns the title of the page or null if none defined

So behavior you have described looks to be correct. Probably information you have found are wrong. I would suggest to rely on official documentation as a main source, and in case of doubts, ask the question in this community .🙂

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @Mahesh_Gunaje,

I do not thing that there is any fallback. According to official documentation:


Returns the title of the page or null if none defined

So behavior you have described looks to be correct. Probably information you have found are wrong. I would suggest to rely on official documentation as a main source, and in case of doubts, ask the question in this community .🙂

Avatar

Level 9

Thanks @lukasz-m   for your quick help.

Mahesh_Gunaje_0-1741086646519.png

I was referring to this one. From many source (Not the official one), I got these details only. May be, this is misleading.

One more help I need. Out of the box breadcrumb feature gives the Navigation title first (if its present). else, Page title. Else, jcr:title

if possible, can you provide me the code snippet from the out of the box breadcrumb feature?

 

Thanks

Avatar

Community Advisor

Avatar

Level 9

Thanks @lukasz-m 

 

Looks like, I have found the code used in out of the box breadcrumb feature.

com.adobe.cq.wcm.core.components.internal.models.v1.PageListItemImpl

/**
* Gets the title of a page list item from a given page.
* The list item title is derived from the page by selecting the first non-blank value from the
* following:
* <ul>
* <li>{@link Page#getNavigationTitle()}</li>
* <li>{@link Page#getPageTitle()}</li>
* <li>{@link Page#getTitle()}</li>
* <li>{@link Page#getName()}</li>
* </ul>
*
* @param page The page for which to get the title.
* @return The list item title.
*/
public static String getTitle(@NotNull final Page page) {
return Stream.<Supplier<String>>of(page::getNavigationTitle, page::getPageTitle, page::getTitle)
.map(Supplier::get)
.filter(StringUtils::isNotBlank)
.findFirst()
.orElseGet(page::getName);
}