Skip to main content
Level 5
Jul 26, 2017 2:28 PM UTC
Solved

Sightly question: how to adapt a class with a path

In java code, I can do this:

Resource articleResource = resourceResolver.getResource("/somepath/for/article");
  Article article = articleResource.adaptTo(Article.class);

Can Sightly do the same? and how?

In AEM 6.3 with sling models.

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
VeenaVikraman
VeenaVikramanAccepted solution
Community Advisor
Jul 26, 2017 2:43 PM UTC

Probably my answer would be yes. Try the below code

  Let me know if it doesn't work

Thanks

Veena

13 replies

VeenaVikraman
Community Advisor
Community Advisor
Jul 26, 2017 8:24 PM UTC

I think @Model(adaptables = Resource.class) and @Model(adaptables = SlingHttpServletRequest.class) both should work

Translate
BigT168Author
Level 5
Jul 26, 2017 8:29 PM UTC

I tried, only adaptables = Resource.class works. Other one returns null after articleResource.adaptTo(Article.class);

Translate
VeenaVikraman
Community Advisor
Community Advisor
Jul 26, 2017 8:39 PM UTC

okay cool. I don't find an option to edit the answer after it is marked correct.

Translate