Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!

Iterates trough child resources looking for the all resources from two specific resourceType


Level 7


I need to find two different resource types in the content and then render these in the correct order as they are stored in the content.


private List<???how to define it???> getRelevantResources(Resource r) {
return ResourceModelUtil.getAllResourcesFromResourceType(r, ???here I would have two resource types???)
.map(resource-> event.adaptTo(??? not sure how to adapt here to two resource types???))


I wrote a conceptual code but I am missing some building blocks that I marked with questionmarks. The idea is that I get a list that I can then render in a template.


Thanks in advance. 

4 Replies


Community Advisor

Is this what you looking for? 


Return as generic resources 

List<Resource> resourceList = new ArrayList<>();
for (Resource resource : resource.getChildren()) {
    if (resource.isResourceType("resourceType1") || resource.isResourceType("resourceType2")) {
return resourceList;

In case, if you want them as the actual component Sling Models  (assuming your sling models extend a generic Component class or use java.util.Object instead)

    List<Component> resourceList = new ArrayList<>();
    for (Resource resource : viewConfigsParent.getChildren()) {
        if (resource.isResourceType("resourceType1")){
        if (resource.isResourceType("resourceType2")){
    return componentList;



Level 7

Hi @Lokesh_Vajrala 

Yes, thank you very much. The first solution is what I was looking for.

I have an additional question if you do not mind.


How do I render a generic resource in the sightly template?

<ul data-sly-list.myList="${model.resourceList}">
<sly data-sly-resource="${???here I need to point to somehow differentiate between the two possible resources???.resource @ resourceType='xxx/components/content/???specific resource???'}"></sly>


I wrote above a conceptual code and left the questionmarks where I am not sure. 


Community Advisor

Well, that's a good question @anasustic

Are you using Sling Models with ModelExporters? If yes, your models may also be implementing ComponentExporter.getExporterType(), in this case, you can call resource.exporterType() which returns the component resourceType.

If you're not using ModelExporters, then with Sling Models, you can add a method getType() to the Model to return the component resourceType to use in HTL/Sightly.


public String getType() {
        return resource.getResourceType();


Level 7

Thank you so much @Lokesh_Vajrala Both of your answers were very helpful. We are using Sling Models.