How to limit number of times list gets iterated in sightly | Community
Skip to main content
Level 3
March 22, 2022
Solved

How to limit number of times list gets iterated in sightly

  • March 22, 2022
  • 1 reply
  • 1947 views

<sly data-sly-list=" ">

<h1> Hello World </h1>

</sly>

 

How to iterate through the loop only 4 times? 

Thanks in advance!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by DEBAL_DAS

Please refer this 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-use-an-integer-value-in-sightly-to-iterate-loop-as-many/m-p/220653

 

If you are dealing with dynamic value then you can use below code -

<ul data-sly-list="${currentPage.listChildren @ begin = 0, end = 3}">
<li>${item.title}</li>
</ul>

 

[

<!--/* if you want to first 5 elements of the list */-->

<ul data-sly-list="${currentPage.listChildren @ begin = 0, end = 4}"> <li>${item.title}</li> </ul>

<!--/* if you want to see from 5th to 10th element */-->

<div data-sly-repeat="${currentPage.listChildren @ begin = 4, end = 9}"> <div>${item.title}</div> </div>

]

https://www.myareapage.com/3-new-features-of-htl-in-aem-6-5/

 

Hope these will help you.

1 reply

DEBAL_DAS
DEBAL_DASAccepted solution
New Member
March 22, 2022

Please refer this 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-use-an-integer-value-in-sightly-to-iterate-loop-as-many/m-p/220653

 

If you are dealing with dynamic value then you can use below code -

<ul data-sly-list="${currentPage.listChildren @ begin = 0, end = 3}">
<li>${item.title}</li>
</ul>

 

[

<!--/* if you want to first 5 elements of the list */-->

<ul data-sly-list="${currentPage.listChildren @ begin = 0, end = 4}"> <li>${item.title}</li> </ul>

<!--/* if you want to see from 5th to 10th element */-->

<div data-sly-repeat="${currentPage.listChildren @ begin = 4, end = 9}"> <div>${item.title}</div> </div>

]

https://www.myareapage.com/3-new-features-of-htl-in-aem-6-5/

 

Hope these will help you.

Debal Das, Senior AEM Consultant
DollyAuthor
Level 3
March 22, 2022

This was helpful. Thank you