Expand my Community achievements bar.

SOLVED

Getting the multifield iteration occurrence

Avatar

Level 7

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>

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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>

 

View solution in original post

7 Replies

Avatar

Community Advisor

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>

 

Avatar

Level 7

Hi @MayurSatav ,

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

 

Avatar

Community Advisor

Hi @JakeCham 

 

Yes i checked actually instead of list name use itemList.

I have already updated the answer

Avatar

Level 7

Hi @MayurSatav 

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

Thanks 

Avatar

Correct answer by
Community Advisor

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>

 

Avatar

Community Advisor

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.