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
BedrockMission!

Learn More

View all

Sign in to view all badges

Iterate through multifield

Avatar

Avatar
Validate 10
Level 2
Gunars_Vilcins
Level 2

Likes

5 likes

Total Posts

34 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Give Back
Ignite 3
Ignite 1
View profile

Avatar
Validate 10
Level 2
Gunars_Vilcins
Level 2

Likes

5 likes

Total Posts

34 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Give Back
Ignite 3
Ignite 1
View profile
Gunars_Vilcins
Level 2

14-05-2021

I have a multifield component which saves to the page like below:

 

Screenshot 2021-05-14 115516.png

 

And I have written this code to iterate through the values and display the nodes in a list:

 

<sly data-sly-test="${resource.hasChildren}" data-sly-list="${resource.getChildren}">
<ul data-sly-test="${item.name == 'items'}" data-sly-list="${item.getChildren}">
<li><a href="${item.path @ extension='html'}">${item.title}</a></li>
</ul>
</sly>

 

The problem is that ${item.path} returns the path of the resource and not the value of 'path' (/content/Page1).

 

The easiest solution would be to change the property name to 'pagePath' but I was wondering if there was another way to retrieve without changing the name.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

570 likes

Total Posts

687 posts

Correct Reply

197 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

570 likes

Total Posts

687 posts

Correct Reply

197 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

15-05-2021

Hi @Gunars_Vilcins 

 

You need to change the property name from 'path' to any other name such as 'pathLink' to resolve it.

It is conflicting with the resource.path object and returning the resource path.

 

Thanks

Answers (1)

Answers (1)

Avatar

Avatar
Boost 10
Level 3
ibishika
Level 3

Likes

22 likes

Total Posts

23 posts

Correct Reply

2 solutions
Top badges earned
Boost 10
Boost 5
Give Back
Applaud 5
Boost 3
View profile

Avatar
Boost 10
Level 3
ibishika
Level 3

Likes

22 likes

Total Posts

23 posts

Correct Reply

2 solutions
Top badges earned
Boost 10
Boost 5
Give Back
Applaud 5
Boost 3
View profile
ibishika
Level 3

14-05-2021

May be you can try defining the list with names instead of using item, so that it explicitly calls the inner list. Something like below:

<sly data-sly-test="${resource.hasChildren}" data-sly-list.outer="${resource.getChildren}">
<ul data-sly-test="${outer.name == 'items'}" data-sly-list.inner="${outer.getChildren}">
<li><a href="${inner.path @ extension='html'}">${inner.title}</a></li>
</ul>
</sly>