Iterate through multifield | Community
Skip to main content
Level 3
May 14, 2021 5:13 PM UTC
Solved

Iterate through multifield

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

 

 

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Asutosh_Jena_
Asutosh_Jena_Accepted solution
New Participant
May 15, 2021 11:20 AM UTC

Hi @gunars_v 

 

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

3 replies

Asutosh_Jena_
Asutosh_Jena_Accepted solution
New Participant
May 15, 2021 11:20 AM UTC

Hi @gunars_v 

 

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

Translate
ibishika
Level 4
May 14, 2021 8:06 PM UTC

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>
Translate
Gunars_VAuthor
Level 3
May 14, 2021 8:16 PM UTC

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

 

Translate