Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Get Subtitle Page Property with HTL

Avatar

Level 3

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 

 

View solution in original post

7 Replies

Avatar

Employee Advisor

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

Avatar

Level 3
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.

Avatar

Community Advisor

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}

Avatar

Correct answer by
Community Advisor

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

 

 

Avatar

Administrator
Thank you for pointing me to this. I have marked this answer as correct.


Kautuk Sahni