HTL sly-list



HTL sly-list

List tag repeats the content of the host element for each enumerable property in the provided object.

For eg:
<h6 data-sly-list="${currentPage.listChildren}">
    <dt>index: ${itemList.index}</dt>
    <dd>value: ${item.title}</dd>
</h6>
Where 'item' is the current item in the iteration & itemList is the object holding the properties.

ItemList Properties:
Property Description
index: zero-based counter (0..length-1).
count: one-based counter (1..length).
first: true if the current item is the first item.
middle: true if the current item is neither the first nor the last item.
last: true if the current item is the last item.
odd: true if index is odd.
even: true if index is even.


Accessing an HTL list value dynamically,

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

1 comment:

  1. Just a quick correction: .even will be true when the count is even, and .odd will be true when the count is odd -- not the index.

    ReplyDelete