Cannot get DefaultSlingScript: data-sly-use needs to be passed an identifier | Community
Skip to main content
Level 6
April 1, 2022

Cannot get DefaultSlingScript: data-sly-use needs to be passed an identifier

  • April 1, 2022
  • 1 reply
  • 2391 views

Hi

When I add to my template

<sly data-sly-use.storeLink="${'android' == model.device ? model.appleStoreLink : model.googlePlayLink}"></sly>

I get the following error

Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: data-sly-use needs to be passed an identifier

My model isDevice looks like:

public String isDevice() {
String userAgent = request.getHeader("user-agent");

if (userAgent.contains("iPhone")) {
return "ios";
} else if(userAgent.contains("Android")){
return "android";
} else {
return StringUtils.EMPTY;
}
}

Any suggestions what I am doing wrong?

  

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Level 2
April 1, 2022

use data-sly-test instead of data-sly-use.

anasusticAuthor
Level 6
April 1, 2022

Hi,

Will this always evaluate:

 

<sly data-sly-test.storeLink="${'android' == model.device ? model.appleStoreLink : model.googlePlayLink}"></sly>

Why does the  

data-sly-use

 throw an error?