looping in HTL sly in AEM | Community
Skip to main content
Level 2
May 23, 2021
Solved

looping in HTL sly in AEM

  • May 23, 2021
  • 3 replies
  • 2561 views

Hi,

 

I need to loop according to given Integer input.

 

Eg - According to user input, i need to repeat to print some HTML elements.

 

if user input is 1,

<div> 1 <div>

 

if user input is 2

<div> 1 <div>

<div> 2 <div>

 

How can i achieve this from HTL.

 

Thanks

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 arunpatidar

HTL does not support traditional looping, arithmetic operations. 

you have to create a list from user input inside the sling Model as suggested by 

and then you can use data-sly-repeat
 

3 replies

ibishika
Level 4
May 23, 2021

Create an Integer List in the Sling Model based on the user input value. Fetch the list in HTL and loop over it.

Level 2
May 23, 2021

You can use sly-list or sly-repeat base on requirement.

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
May 24, 2021

HTL does not support traditional looping, arithmetic operations. 

you have to create a list from user input inside the sling Model as suggested by 

and then you can use data-sly-repeat
 
Arun Patidar