0
votes

data-sly-resource tag allows to refer resource in another component in following way.

<article data-sly-resource="path/to/resource"></article>

We have path/to/resource being taken as part of dialog field by content authors. If the content authors select the path which is not existing by mistake, page becomes inaccessible to content authors, giving HTTP 500 error and there is no other way to correct it without going to CRX. On environments where access to CRX is not there, we cannot delete the incorrect node. Exception in logs is

Caused by: org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.resource.ResourceNotFoundException: No resource found
at com.adobe.cq.sightly.WCMScriptHelper.includeResource(WCMScriptHelper.java:143)
at com.adobe.cq.sightly.WCMScriptHelper.includeResource(WCMScriptHelper.java:86)
at com.adobe.cq.sightly.internal.extensions.ResourceExtension.call(ResourceExtension.java:99)
at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:89)

The out of the box reference component (/libs/foundation/components/reference/reference.jsp) handles this by having a catch block, Content Author can correct path. But that's JSP based not sightly based.

Is there a way to handle this in sightly?

2

2 Answers

2
votes

The proper way to handle this is through an Use-API object that will attempt to find the resource and handle any exceptions:

<article data-sly-use.helper="myHelper" data-sly-test="${helper.resource}" data-sly-resource="${helper.resource}"></article>

Passing an actual org.apache.sling.api.resource.Resource to data-sly-resource is possible since SLING-5811, for older versions of HTL/Sightly you will need to pass a path.

-1
votes

Try this syntax, path should given in EL expression:

<article data-sly-resource="${ @ path='path/to/resource'}"></article>