Add attribute in Sightly HTL only if it exists (AEM) Here all three options of approaching this Sling Model Using sling models is the preferred way because it provides a better separation of concerns and keeps your HTL clean and you can write tests for your model
aem - Sightly (HTL) List iteration - Stack Overflow You can either use data-sly-list or data-sly-repeat to iterate over collections iterables in HTL Both of them work the same with the only difference, data-sly-repeat doesn't require a container whereas data-sly-list requires one