September 24, 2026

HTL data-sly-list: Iterating Over Lists and Maps

HTL sly-list

data-sly-list repeats the content of the host element for each enumerable property of the provided object.

<dl data-sly-list="${currentPage.listChildren}">
    <dt>index: ${itemList.index}</dt>
    <dd>value: ${item.title}</dd>
</dl>

Here item is the current item in the iteration, and itemList is the object holding the properties below.

itemList properties

PropertyDescription
indexzero-based counter (0..length-1)
countone-based counter (1..length)
firsttrue if the current item is the first item
middletrue if the current item is neither the first nor the last item
lasttrue if the current item is the last item
oddtrue if index is odd
eventrue if index is even

Accessing a list value dynamically

<dl data-sly-list.child="${myList}">
    <dt>key: ${child}</dt>
    <dd>value: ${myList[child]}</dd>
</dl>

To repeat the element itself rather than its content, use data-sly-repeat.

Back to the HTL tutorial index