Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Iterate through multifield

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Level 6

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>

Avatar

Level 3

Thanks for the quick reply ibishika. I've tried that and unfortunately it still returns the resource path as the url.

It returns this: /content/myTestPage/_jcr_content/myComponent/items/item0.html

 

Avatar

Correct answer by
Community Advisor

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