Get Subtitle Page Property with HTL

JonMaguire

09-09-2020

I'm wanting to retrieve the page subtitle and description using HTL. Using the AEM HTL Read–Eval–Print Loop environment to test, I'm able to get the description using ${item.description} but cannot get subtitle using the same format, ${item.subtitle}. Is there a different way to get the subtitle property?

Accepted Solutions (1)

Accepted Solutions (1)

ChitraMadan

MVP

09-09-2020

Hi @JonMaguire ,

 

If your page has title and subtitle as shown below, it can be retrieved as:

 

Screenshot 2020-09-09 at 21.47.03.png

 

<ul data-sly-list="${currentPage.listChildren}">
<li>${item.title}</li>
<li>${item.properties.subtitle}</li>
</ul>

 

ChitraMadan_0-1599685547860.png

 

 

Answers (2)

Answers (2)

Vijayalakshmi_S

MVP

09-09-2020

Hi @JonMaguire,

In your snippet, if "item" is a Page object, then item.subtitle won't work as there is no getter exposed/available for the property subtitle in Page API(com.day.cq.wcm.api.Page)

You can retrieve the same using Resource API as ${resource.valueMap.subtitle}

Jörg_Hoh

Employee

09-09-2020

This works because the page resource (more exactly: the jcr:content resource) does have a property named "description". If you add a property called "subtitle", you can also reference this in HTL via ${item.subtitle}.