Expand my Community achievements bar.

SOLVED

HTL/Sightly: How to access individual values in an array? (not sure if it's an array)

Avatar

Level 9

So I have the code below (which I got from Sightly how to get multivalued properties )

<dl data-sly-list.head="${properties.testimonials}">

    <dt>key: ${head}</dt>

</dl>

and this gives me

key: {"testimonialPath":"/content/myhost/en/testimonials/hr/about"}
key: {"testimonialPath":"/content/myhost/en/testimonials/hr/work-safety"}
key: {"testimonialPath":"myhost/en/testimonials/hr/vacancy"}
How can I access the values that start with"/content"?
I tried
<dl data-sly-list.head="${properties.testimonials}">
    <dt>key: ${head[testimonialPath]}</dt>
</dl>

And my page won't load because of an error. I then tried

<dl data-sly-list.head="${properties.testimonials}">
    <dt>key: ${head["testimonialPath"]}</dt>
</dl>

and while there's no error, I also doesn't display the value.

Can you please help? Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

If you want to return only values that start with /content - i recommend using Java business logic to filter the ArrayList and then display those values.

View solution in original post

2 Replies

Avatar

Level 10

See this article where we work with Collections and HTL. The Java part of the HTL returns a Java collection and the HTL iterates over it and renders the values:

Scott's Digital Community: Creating an Adobe Experience Manager HTL component that displays a repeat...

<div data-sly-test="${ibeanObj.lBean}" data-sly-list.items="${ibeanObj.lBean}">

                  <div style="height:250px;"><img src=${items.path} height=200 width=270 style="padding:4px"/><h2>${items.page}</h2>

                             <p>${items.desc}</p>

                                

                             </div>

                             <hr>

                    </div>

Avatar

Correct answer by
Level 10

If you want to return only values that start with /content - i recommend using Java business logic to filter the ArrayList and then display those values.