0

Currently I had a requirement to access the elements of Map from List. Please see the below sample code snippet.

List<Map> listOfMap = new Hash();

Map hmap1 = new HashMap();
hmap1.put("name","Rob");
hamp1.put("class","I");

Map hmap2 = new HashMap();
hmap2.put("subjects","{subject1:Maths, subject2:Englsih}");
listOfMap.add(hamp2);

Now in sightly I have to access and display this map elements from list. Can any one suggest me how to do this.

toniedzwiedz
  • 17,895
  • 9
  • 86
  • 131
mchinta
  • 272
  • 1
  • 2
  • 16

1 Answers1

2

You will need to expose the list via an Use-Object (Sling Model, POJO or Javascript). Then you can iterate items using data-sly-list, for example:

<ul data-sly-use.logic="..." data-sly-list.listItem="${logic.list}">
    <li>${listItem.size} items:
        <ul data-sly-list.mapItem="${listItem.keySet}">
            <li>${mapItem} - ${listItem[mapitem]}</li>
        </ul>
    </li>
</ul>
Vlad
  • 10,602
  • 2
  • 36
  • 38