Map In Sighly | Community
Skip to main content
Ricky99999
Level 4
Sep 19, 2017 12:06 PM UTC
Solved

Map In Sighly

How to Iterate a Map In Sightly

In my use class I hava a Map like these

Map<Integer,String> hm=new HashMap<Integer, String>();

@Override

public void activate() throws Exception {

// TODO Auto-generated method stub

hm.put(1, "aaaaaaaaaa");

hm.put(2,"bbbbbbbbbb");

hm.put(3,"cccccccccccccc");

}

How to iterate keys and values in sightly

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
edubey
edubeyAccepted solution
Level 10
Sep 19, 2017 12:38 PM UTC

I think this has been answered in many questions, so should be easy for you.


Do refer below code from Feike Visser

Here an example the shows how it can be done, without java code.

https://github.com/heervisscher/htl-examples/blob/master/core/src/main/java/com/adobe/exam ples/htl/core/hashmap/HashMapExample.java

HTL-code:

<div data-sly-use.hashmap="com.adobe.examples.htl.core.hashmap.HashMapExample"
     data-sly-list="${hashmap.map.keySet.iterator}">
     ${item}
     <ul data-sly-list.aem="${hashmap.map[item].keySet.iterator}">
         <li>${aem} ${hashmap.map[item][aem]}</li>
     </ul>
</div>

Also other links

CQ5 AEM Basics: Iterate Map and List in Sightly | Map of List in sightly | AEM CQ5

Accessing Hashmap in Sightly · GitHub

3 replies

Ricky99999
Level 4
Sep 20, 2017 5:24 AM UTC

Thanks

Translate
smacdonald2008
Level 10
Sep 19, 2017 2:26 PM UTC

We have a lot of articles that show you how to iterate through collections in HTL - see this one:

Scott's Digital Community: Creating an Adobe Experience Manager HTL component that displays a repeating data set

Translate
edubey
edubeyAccepted solution
Level 10
Sep 19, 2017 12:38 PM UTC

I think this has been answered in many questions, so should be easy for you.


Do refer below code from Feike Visser

Here an example the shows how it can be done, without java code.

https://github.com/heervisscher/htl-examples/blob/master/core/src/main/java/com/adobe/exam ples/htl/core/hashmap/HashMapExample.java

HTL-code:

<div data-sly-use.hashmap="com.adobe.examples.htl.core.hashmap.HashMapExample"
     data-sly-list="${hashmap.map.keySet.iterator}">
     ${item}
     <ul data-sly-list.aem="${hashmap.map[item].keySet.iterator}">
         <li>${aem} ${hashmap.map[item][aem]}</li>
     </ul>
</div>

Also other links

CQ5 AEM Basics: Iterate Map and List in Sightly | Map of List in sightly | AEM CQ5

Accessing Hashmap in Sightly · GitHub

Translate