Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

looping in HTL sly in AEM

Avatar

Avatar
Validate 1
Level 1
Nesan
Level 1

Likes

0 likes

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
Nesan
Level 1

Likes

0 likes

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
Nesan
Level 1

23-05-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,356 likes

Total Posts

3,227 posts

Correct Reply

917 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,356 likes

Total Posts

3,227 posts

Correct Reply

917 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

24-05-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
 

Answers (2)

Answers (2)

Avatar

Avatar
Boost 10
Level 2
ibishika
Level 2

Likes

17 likes

Total Posts

16 posts

Correct Reply

1 solution
Top badges earned
Boost 10
Boost 5
Give Back
Applaud 5
Boost 3
View profile

Avatar
Boost 10
Level 2
ibishika
Level 2

Likes

17 likes

Total Posts

16 posts

Correct Reply

1 solution
Top badges earned
Boost 10
Boost 5
Give Back
Applaud 5
Boost 3
View profile
ibishika
Level 2

23-05-2021

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

Avatar

Avatar
Boost 1
Level 1
Sanket_Dange
Level 1

Like

1 like

Total Posts

16 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Give Back
Ignite 1
Validate 1
View profile

Avatar
Boost 1
Level 1
Sanket_Dange
Level 1

Like

1 like

Total Posts

16 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Give Back
Ignite 1
Validate 1
View profile
Sanket_Dange
Level 1

23-05-2021

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