Sling Model in AEM6.0 - How to get the path of the original resource | Community
Skip to main content
johndoe42
New Participant
October 16, 2015
Solved

Sling Model in AEM6.0 - How to get the path of the original resource

  • October 16, 2015
  • 2 replies
  • 2133 views

Hi

I'm currently using Sling Models to adapt several Resources to customized models. One of my models must be aware of the original resource it was adapted from (I basically need the name of the node but I guess it wouldn't hurt to have the full path as it will provide me with more flexibility). It seems that @SlingObject is what I'm looking for. Unfortunately AEM 6.0 is using Sling Models 1.0.x and SlingObject requires 1.1.x or so. Updating to AEM 6.1 is currently no option so I was wondering if there is any other way that would get me the information I need.

As an alternative I could install the 1.1.x bundles in AEM6.0 but I'm not sure if it is safe to do so. I'm pretty sure it won't break our custom code but what about the AEM6 code base?

Any advice/help is greatly appreciated.

Cheers

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 francisco_ribei

You can use the :

@Source('sling-object')

It will have the same effect as @SlingObject

 

Att.

2 replies

francisco_ribei
francisco_ribeiAccepted solution
New Participant
October 16, 2015

You can use the :

@Source('sling-object')

It will have the same effect as @SlingObject

 

Att.

johndoe42
johndoe42Author
New Participant
October 16, 2015

Hi

Thank you for your response. Unfortunately it doesn't seem to work for me in this particular case (original object was of type Resource.class). However I was able to get the resource by simply adding @Inject private Resource resource; to the class in question. I'll keep the @Source annotation in mind though. Thanks again for your help.

Cheers