0
votes

I have created Sling model which is fetching the root page and its child pages. I added the title and description of all the pages in List.

My bean class is as follows

Items(String title, String description, List<Items>)

I have list of this Items bean class in my sling model and added the content in this list. List<Items> in parameter is for the child pages to be stored in it.

How can I fetch this list values in my HTL code to display it on page using sightly? What will be the code for this?

1

1 Answers

1
votes

You would normally expose the list of times with a getter method:

public List<Items> getItems() { ... }

Assuming each items also exposes getters for title and description:

public String getTitle() { ... }
public String getDescription() { ... }

Then you can just use your model:

<ul data-sly-use.myModel="MyModelClass" data-sly-list="myModel.items">
    <li>${item.title} - ${item.description}</li>
</ul>

There are some more examples in the HTL specification.