Get Subtitle Page Property with HTL | Community
Skip to main content
JonMaguire
Level 3
Sep 9, 2020 7:07 PM UTC
Solved

Get Subtitle Page Property with HTL

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
ChitraMadan
ChitraMadanAccepted solution
New Participant
Sep 9, 2020 9:03 PM UTC

Hi @jonmaguire ,

 

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

 

 

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

 

 

 

7 replies

ChitraMadan
ChitraMadanAccepted solution
New Participant
Sep 9, 2020 9:03 PM UTC

Hi @jonmaguire ,

 

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

 

 

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

 

 

 

Translate
JonMaguire
Level 3
Sep 10, 2020 3:01 PM UTC
This should be the accepted answer.
Translate
Vijayalakshmi_S
Level 10
Sep 9, 2020 8:10 PM UTC

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}

Translate
joerghoh
Employee
Sep 9, 2020 7:52 PM UTC

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}.

Translate
JonMaguire
Level 3
Sep 10, 2020 3:00 PM UTC
I don't know why this was marked as accepted. @chitramadan's answer below should be the accepted solution. ${item.subtitle} does not work. ${item.properties.subtitle} does work.
Translate