Getting the multifield iteration occurrence | Community
Skip to main content
JakeCham
Level 6
September 3, 2021
Solved

Getting the multifield iteration occurrence

  • September 3, 2021
  • 2 replies
  • 1815 views

Hi Team,

 

I'm working on a requirement where nested multifields should be there. So I came up with an approach there I haven't used any js to retrieve nested multifields values. But now I want to get the iteration number(occurrence) for parent multifield. I will put the sample code and will show at where I want to take the iteration number. Any help would be appreciated.

 

<sly data-sly-list-firstmultifield="${resource.getChildren}">

   <sly data-sly-test="${firstmultifield.name=='item1'}">

      <sly data-sly-list-firstMenuItems="${firstmultifield.getChildren}">

           //here need to get the iteration number  (like first iteration,second iteration something like itemList.count) of multifield named item 1

        <sly data-sly-list-seconmultifield = "${firstMenuItems.getChildren}">

            <sly data-sly-test="${seconmultifield .name=='item2'}">

                 <sly data-sly-list-secondMenuItems="${seconmultifield .getChildren}">

                       //here need to get the iteration number of multifield named item 2

                  </sly>

           </sly>

        </sly>

    </sly>

  </sly>

</sly>

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Vijayalakshmi_S

Hi @mayursatav 

  I tried that but still not working. Have you tried the same scenario ?

Thanks 


Hi @jakecham,

It should be the list Identifier name (in this case, you have used firstMenuItems and secondMenuItems) followed by the term "List". Example below for clarity

 

<dl data-sly-list.firstMenuItems="${currentPage.listChildren}">
    <dt>index: ${firstMenuItemsList.index}</dt>
    <dd>value: ${firstMenuItems.title}</dd> // any property part of the list item.
</dl>

If we aren't using any, default variable to access the index and individual item is itemList and item respectively

 

<dl data-sly-list="${currentPage.listChildren}"> <dt>index: ${itemList.index}</dt> <dd>value: ${item.title}</dd> </dl>

 

2 replies

MayurSatav
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 3, 2021

Hi @jakecham 

 

For iterration number you can use 

 

<sly data-sly-list-firstMenuItems="${firstmultifield.getChildren}">
    <p>${itemList.index}</p>
</sly>

to get the iteration number of multifield named item 2

 <sly data-sly-list-secondMenuItems="${seconmultifield .getChildren}">
            <sly data-sly-test="${itemList.index == 2}" data-sly-unwrap>
                <p> ${itemList.index}</p>
            </sly>
 </sly>

 

Mayur Satav | www.mayursatav.in
JakeCham
JakeChamAuthor
Level 6
September 3, 2021

Hi @mayursatav ,

Thanks for the  reply. I have checked this but it is not working. Have you tried this ?

 

MayurSatav
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 3, 2021

Hi @jakecham 

 

Yes i checked actually instead of list name use itemList.

I have already updated the answer

Mayur Satav | www.mayursatav.in
Kiran_Vedantam
Community Advisor
Community Advisor
September 3, 2021

Hi @jakecham,

 

It is always suggested to write the above code in sling models and fetch the values from there.

 

Check my blog here: https://allaembykiran.wordpress.com/2021/01/13/nested-multi-field/

 

Hope this helps!

 

Thanks,

Kiran Vedantam.