Expand my Community achievements bar.

Slightly - Nav Component Extension

Avatar

Level 2

Hi Team,

 

In my current project there is a requirement to build a Navigation Component with the addition of a categorized order which each child page will be mapped to its respective category. Something like below:

 

Parent Page (home)

  • Offers
  • Guidance
  • Pet Guides
    • Dog
      • How to train your dog
      • Producs to take care of your dog
    • Cat
      • 10 Tips to take care of your cat
    • Reptile

 

My first idea was to implement a method with this kind or return type "

List<HashMap<String,List<NavigationItem>>> getCategorizedItems().

The list insertion is doing fine but in Slightly, I'm not able to iterate over the second list that is inside the Hashmap. Is this a good approach?. if not, It'd helpful for me gather your suggestions for a better way to handle this scenario.

 

I checked some post "almost related" for iterating but none of them worked for me (not sure if I'm missing something or even if it's possible).

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sightly-how-to-iterate-map...

 

Any guidance that you can give me guys. I'll be appreciate it.

 

 

Regards

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Community Advisor

Hi, 

 

I think you should use a couple of sling models with the @ChildResource annotation, this is more clean and follow the best practices. If this gets more complex, perhaps even using a JSON structure is not a bad idea.

 

You can learn more about the annotation here:

https://allaembykiran.wordpress.com/2021/01/13/nested-multi-field/ 

https://www.digitalum.eu/blog/english/sling-models-part-4-structure-nodes-and-build-models/ 

https://sling.apache.org/documentation/bundles/models.html#available-injectors 

 

Hope this helps.



Esteban Bustamante

Avatar

Administrator

@Luis_Ochoa Did you find the suggestion helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni