Sightly question: how to adapt a class with a path | Community
Skip to main content
Level 5
July 26, 2017
Solved

Sightly question: how to adapt a class with a path

  • July 26, 2017
  • 13 replies
  • 6757 views

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.
Best answer by VeenaVikraman

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
July 26, 2017

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

BigT168Author
Level 5
July 26, 2017

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

VeenaVikraman
Community Advisor
Community Advisor
July 26, 2017

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