Expand my Community achievements bar.

SOLVED

Trying to iterate in sightly

Avatar

Level 3

Hi,

I have one requirement where i have one multivalue field and based on that am trying to iterate by using data-sly-list.

My filed is dc:title which i have made multifield and thrn iterating like below:

<sly data-sly-list="${asset.properties['dc:title']}">

// my code

</sly>

Now lets say i have values abc, xyz and i want in 1st iteration only abc should come but value is coming in coma-separated form as abc,xyz.

How can i handle this??

Thanks in advance,

Regards,

Lovepreet

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

It will best if you add sling models to your multifield resource (component) and iterate like below

<div

    data-sly-use.multiItems="aem.community.mf.core.models.Multifield">

    <div data-sly-list.head="${multiItems.products.listChildren}">

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

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

     </div>

   </div>

Above example provide by smacdonald2008​ gives you idea about sling models

Also refer https://blogs.perficientdigital.com/2018/08/24/using-sling-models-with-nested-composite-mulitifields...

Hope this helps !

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi,

It will best if you add sling models to your multifield resource (component) and iterate like below

<div

    data-sly-use.multiItems="aem.community.mf.core.models.Multifield">

    <div data-sly-list.head="${multiItems.products.listChildren}">

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

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

     </div>

   </div>

Above example provide by smacdonald2008​ gives you idea about sling models

Also refer https://blogs.perficientdigital.com/2018/08/24/using-sling-models-with-nested-composite-mulitifields...

Hope this helps !

Avatar

Level 4

This will happen when value of dc:title multi-field property is saved as string in node as comma separated.

Please check, and update multi-field logic in dialog to save as String array. With string array it should work fine.

<ul data-sly-list="${ [1,2,3,4] }">
<li>${item}</li>
</ul>