Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

When use data-sly-use.multifield="${resource.path}/field" getting sling error

Avatar

Level 2

I am getting below error when add the component in the AEM new page. Kindly suggest the correction, if anyone have the idea for code changes. 

 

ERROR:

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: No use provider could resolve identifier /***********_header/field

Cannot serve request to /content/project/path/test.html in /apps//project/path/webhelp-header/webhelp-header.html

Exception:

org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.a

 

My code in html:

<div class="contentArea" id="${properties.id}">
<h1>${properties.title}</h1>
</br>
<sly data-sly-use.multifield="${resource.path}/field"/>
        <sly data-sly-list.item=${multifield.listChildren}>
<h2>${item.text}</h2>
<p>${item.termDef  @CONTEXT='html'}</p>
</sly>
</sly>
</br>
<P align="right" style="margin-right:30px"><a href="#top" TITLE="Back to top"><B>^</B></A></P>
<p>&nbsp;</p>
 
</div>

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi @MohanasundaramMo 

where is the your file named field and have you create a model class for it because what i can see you are using resource.path, in Sightly refers to the absolute path of the current resource within the AEM content repository

If your component is included on a page located at /content/mysite/en/products/myproduct, then resource.path would return /content/mysite/en/products/myproduct
what i would suggest that If the script file (field) is located within the same folder as your component, use a relative path:

data-sly-use.multifield="./field" // "./" refers to the current component's folder

If you're using a Sling Model for the multifield functionality, the attribute should reference the model class path:

data-sly-use.multifield="com.your.package.FieldModel" // Replace with your actual model class path

feel free to reply if you need further clarifications.

Hope this helps!


View solution in original post

6 Replies

Avatar

Level 7

Hi @MohanasundaramMo 

AEM cannot find the script associated with the data-sly-use.multifield, In your case, it's looking for a script with the identifier /_header/field also i noticed

The data-sly-list attribute should be enclosed in double quotes.
You have nested <sly> tags, which is not necessary in this case. You can simplify it by removing the inner <sly> tag.

Check below blog to see the use case of HTL Java Use-API
https://experienceleague.adobe.com/en/docs/experience-manager-htl/content/java-use-api 

Avatar

Level 2

Hi Abhishek,

 

Thanks for the quick response.

 

After mode the changes also based on you suggestion still getting same error. i thought  "<sly data-sly-use.multifield="${resource.path}/field">" multifield need to change i am not sure how to change that. This same used some components for existing our project but all component not working with this check.

corrected code:

<sly data-sly-use.multifield="${resource.path}/field">
<sly data-sly-list.item="${multifield.listChildren}">

<a class="grayButton" data-sly-element="${!item.enableLink? 'span':'a'}" href="${item.link @Extension='html'}" >${item.button} </a>
</sly>
</sly>

 

Thanks,

Mohan

Avatar

Correct answer by
Level 7

Hi @MohanasundaramMo 

where is the your file named field and have you create a model class for it because what i can see you are using resource.path, in Sightly refers to the absolute path of the current resource within the AEM content repository

If your component is included on a page located at /content/mysite/en/products/myproduct, then resource.path would return /content/mysite/en/products/myproduct
what i would suggest that If the script file (field) is located within the same folder as your component, use a relative path:

data-sly-use.multifield="./field" // "./" refers to the current component's folder

If you're using a Sling Model for the multifield functionality, the attribute should reference the model class path:

data-sly-use.multifield="com.your.package.FieldModel" // Replace with your actual model class path

feel free to reply if you need further clarifications.

Hope this helps!


Avatar

Level 2

Thanks for suggestion. after implement new sling model changes works good.

Avatar

Community Advisor

It seems you are just trying to iterate over some composite multifield set in your component. If I have to take a guess your content structure looks something like 

componentNode
  field
    item0
    item1

So to get the multifield properties and iterate, you could possibly do something like 

<sly data-sly-list.childResource="${resource.children}">
  <sly data-sly-test="${childResource.name =='field'}" data-sly-list="${childResource.children}">
    <a class="grayButton" data-sly-element="${!item.enableLink? 'span':'a'}" href="${item.link @ extension='html'}" >${item.button} </a>
  </sly>
</sly>

Ofcourse this is just sample, you can do it better in a sling model as Abhishek suggested.
Hope this helps

Avatar

Community Advisor

To retrieve values from multiple fields, we typically use Sling Model. You can refer to the article for step-by-step instructions.

https://ms-29.com/aem/sites/fetch-multifield-values-using-sling-model