Expand my Community achievements bar.

SOLVED

looping in HTL sly in AEM

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Level 6

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

Avatar

Level 2

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

Avatar

Correct answer by
Community Advisor

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