Skip to main content
Level 2
mai 23, 2021 7:30 AM UTC
Répondu

looping in HTL sly in AEM

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

Ce sujet a été fermé aux réponses.
arunpatidar
arunpatidarRéponse
Community Advisor
mai 24, 2021 12:29 PM UTC

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

3 commentaires

ibishika
Level 4
mai 23, 2021 9:56 AM UTC

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

Traduire
Level 2
mai 23, 2021 1:38 PM UTC

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

Traduire
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorRéponse
Community Advisor
mai 24, 2021 12:29 PM UTC

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
 
Traduire
Arun Patidar