I have a simple sling model, the important part looks like this:
This works fine if I use HTL's <data-sly-use="..."> in a component to access resources under the page where the component is used.
However, if my component is used in the structure of an editable template, this breaks since the resources I want are in the template node, not the page node.
Is there a way to access the template resource node instead?
Views
Replies
Total Likes
Checking this with the Team.
Views
Replies
Total Likes
You can bind nodes in the AEM JCR like this. Create a Resource that points to the node in the AEM JCR - an editable template in your example:
Resource resource = resolver.getResource("/content/testsling/slingmodel");
ValueMap valueMap=resource.adaptTo(ValueMap.class);
response.getWriter().write("Output from ValueMap is First Name: "+valueMap.get("firstName").toString()+" Last Name: "+valueMap.get("lastName").toString()+" Technology: "+valueMap.get("technology").toString()+"");
UserInfo userInfo = resource.adaptTo(UserInfo.class);
response.getWriter().write("Output from Sling Model is First Name: "+userInfo.getFirstName()+" Last Name: "+userInfo.getLastName()+" Technology: "+userInfo.getTechnology());
Using this - you can base a Sling Model on JCR nodes.
Adobe Experience Manager Help | Creating Adobe Experience Manager 6.3 Sling Model Components
Hope this helps....
Views
Replies
Total Likes
Hey,
Try to adapt sling model with {SlingHttpServletRequest.class} and use @ValueMapValue annotation over fields.
Thanks,
Himanshu
Views
Replies
Total Likes
I looked into @ValueMapValue and @Via but did not see anything that would automatically "walk" the JCR back to the template. As a work-around I hard-coded a JCR path as in smacdonald2008's suggestion, but would like to refactor this for better maintainability/re-use.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies