Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

How to access nested properties?

Avatar

Ehemaliges Community-Mitglied

Hello,

I have the following nested properties in one of my pages:

1324810_pastedImage_0.png

I'm unable to access these properties with HTL:

1324931_pastedImage_1.png

Any info on this will be great.

Thanks...

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Community Advisor

Hi Akash,

You could get children of carouselImages in a list using Sling model or WcmUse Api like this:

private java.util.List<Resource> list;

final Resource resource = request.getResource();

Resource childResource = resource.getChild("links");

Iterator<Resource> resources = resource.listChildren();

while (resources.hasNext()) {

list.add(resources.next());

}

And, then using that model in sighly using

<sly data-sly-use.model="org.sample.Model"></sly>

<sly data-sly-list=${model.list}>

{item.<property-name>}

</sly>

Lösung in ursprünglichem Beitrag anzeigen

4 Antworten

Avatar

Level 3

try ${properties["carouselImages/item0/isActive"]}

Avatar

Ehemaliges Community-Mitglied

Hi awadheshv​,

This sure is helpful and thank you for replying.

The only issue with hard-coding item0 is that there could be n number of items and cannot be known when building the component.  Is there a way to iterate over the items that is under carouselImages?

Something like:

<ol data-sly-list="${properties['carouselImages']}">
     <li>${item.isActive}</li>
     <li>${item.url}</li>
</ol>

Regards...

Avatar

Korrekte Antwort von
Community Advisor

Hi Akash,

You could get children of carouselImages in a list using Sling model or WcmUse Api like this:

private java.util.List<Resource> list;

final Resource resource = request.getResource();

Resource childResource = resource.getChild("links");

Iterator<Resource> resources = resource.listChildren();

while (resources.hasNext()) {

list.add(resources.next());

}

And, then using that model in sighly using

<sly data-sly-use.model="org.sample.Model"></sly>

<sly data-sly-list=${model.list}>

{item.<property-name>}

</sly>

Avatar

Ehemaliges Community-Mitglied

The other answers have been very helpful.  I have also tried something with server-side-Javascript and this snippet of code is what i'm working with:

var carouselImageNodes, carouselImages;

//

setCarouselImageNodes();

setCarouselImages();

//

function setCarouselImageNodes(){

        carouselImageNodes = {};

        if(typeof this.currentNode != 'undefined') {

            carouselImageNodes = this.currentNode.hasNode("carouselImages") ?

                this.currentNode.getNode("carouselImages").getNodes() :

                {};

        }

}

function setCarouselImages() {

        carouselImages = Object.keys(carouselImageNodes).map(function(key){

            return {

                url: properties['carouselImages/'+ key +'/url'],

                isActive: properties['carouselImages/'+ key + '/isActive'],

                caption: {

                    heading: {

                        element: properties['carouselImages/'+ key + '/caption/heading/element'],

                        text: properties['carouselImages/'+ key + '/caption/heading/text']

                    },

                    paragraph: {

                        element: properties['carouselImages/'+ key + '/caption/paragraph/element'],

                        text: properties['carouselImages/'+ key + '/caption/paragraph/text']

                    }

                }

            };

});

Thanks & Good Luck...