Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Getting the multifield iteration occurrence

JakeCham
Level 4
Level 4

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
Vijayalakshmi_S
Correct answer by
Community Advisor
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

2 Replies
mayur_satav
Level 3
Level 3

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>

 

JakeCham
Level 4
Level 4

Hi @mayur_satav ,

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

 

mayur_satav
Level 3
Level 3

Hi @JakeCham 

 

Yes i checked actually instead of list name use itemList.

I have already updated the answer

JakeCham
Level 4
Level 4

Hi @mayur_satav 

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

Thanks 

Vijayalakshmi_S
Correct answer by
Community Advisor
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

KiranVedantam1992
Community Advisor
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.