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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Is it possible to iterate through an array (or another data type) using HTL?

jayv25585659
Level 6
Level 6

if yes, can you please provide an example or maybe a link to one?

 

Thanks!

1 Accepted Solution
asutosh_jena
Correct answer by
Community Advisor
Community Advisor

Hi @jayv25585659 

You can use the logic in Model class in java and then call the model class in HTL to achieve the use case.

Please see the list feature that HTL provides:

https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#226-list

 

Thanks!

View solution in original post

2 Replies
asutosh_jena
Correct answer by
Community Advisor
Community Advisor

Hi @jayv25585659 

You can use the logic in Model class in java and then call the model class in HTL to achieve the use case.

Please see the list feature that HTL provides:

https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#226-list

 

Thanks!

View solution in original post

jayv25585659
Level 6
Level 6

- Are you saying I need to convert my array into a list of objects/model first? Thank you

asutosh_jena
Community Advisor
Community Advisor

@jayv25585659 

Yes. You should convert array into List in Java using the Sling Model and use the model object to iterate it in HTL.

 

Thanks!

Bimmi_Soi
Community Advisor
Community Advisor

Hi @jayv25585659 ,

 

You can create a list using your array in sling model and then in htl using sightly you can iterate over the same

<ul data-sly-list="${model.yourList}">
    <li>${item.property}</li>
</ul>

Hope this helps!!

Thanks 

jayv25585659
Level 6
Level 6

Are you saying I need to convert my array into a list of objects/model first? Thanks

Bimmi_Soi
Community Advisor
Community Advisor

@jayv25585659 : Yes, create a list using your array in sling model and then in htl using sightly you can iterate over the same

 

Thanks!!!