Actually, I need to get the multifield count in the component, and then I need to use that count in the HTL. Is there any way to get the multifield count?
Solved! Go to Solution.
Views
Replies
Total Likes
@Ameen_Dev HTL does not offer a way to get the list size either, however it allows getting interesting properties of the current item:
* index: zero-based counter (0..length-1); * count: one-based counter (1..length); * first: true for the first element being iterated; * middle: true if element being iterated is neither the first nor the last; * last: true for the last element being iterated; * odd: true if count is odd; * even: true if count is even.
e.g. If you want to display the whole list count
<sly data-sly-test.totalItems="${0}"></sly> <sly data-sly-list.child="${resource.listChildren}"> <sly data-sly-test.totalItems="${ childList.count }"></sly> </sly>
${ totalItems } - this will give you the number of items in the list.
Thanks
Hi @Ameen_Dev ,
You already might be using a model to get the multi data, that multi is returned as a list which you can iterate in HTL.
Since, your backend code Resource#listChildren will return an Iterator<Resource>, you will not be able to get the size of the list of children from there.
Either you can , make use of current item properties :
// iterate and check if thats the last item, if yes -> return the count
<sly data-sly-list.demo=“${demo123.items.listChildren}”> <sly data-sly-test=“${demoList.last}”> ${demoList.count} </sly>
Or you can declare a variable for itemList and use .length :
<sly data-sly-list.item="resource.listChildren"> <sly data-sly-list.itemList="item.listChildren"> ${itemList.length} </sly> </sly>
Hope this helps!
Thanks,
Milind
@Ameen_Dev HTL does not offer a way to get the list size either, however it allows getting interesting properties of the current item:
* index: zero-based counter (0..length-1); * count: one-based counter (1..length); * first: true for the first element being iterated; * middle: true if element being iterated is neither the first nor the last; * last: true for the last element being iterated; * odd: true if count is odd; * even: true if count is even.
e.g. If you want to display the whole list count
<sly data-sly-test.totalItems="${0}"></sly> <sly data-sly-list.child="${resource.listChildren}"> <sly data-sly-test.totalItems="${ childList.count }"></sly> </sly>
${ totalItems } - this will give you the number of items in the list.
Thanks
Thanks for your solution. It worked as expected.
Views
Likes
Replies