I have a resource stored under in '/libs/settings/wcm/designs/default/jcr:content/main/content/links'.
I need to read the properties(or say values) of that resource using Sling Model?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
if you use the design dialog, why don't you use the Designer API, which abstracts this for you.
For example: Design ("The Adobe AEM Quickstart and Web Application.")
(seems that there is some issue with the AEM 6.4 javadoc for this class; I just verified that the API still exists as of AEM 6.4, so you can use it.)
For long-term stability, I would recommend you to consider the new Style system, which is the new way to build templates and components (combined with Editable templates).
Modifying nodes in /libs is violating best practices, and should only be done when instructed so by Adobe support.
Do you have an existing sling model, which needs to access this data, or do you want to create a new sling model to read the data from there?
Jörg
Views
Replies
Total Likes
Okay I understand.
Actually the path('/libs/settings/wcm/designs/default/jcr:content/main/content/links') is where my Design Dialog values are getting stored. So i need to create a sling model that can read values from that path.
Views
Replies
Total Likes
Create overlay in /apps to manage your design properties and then read it accordingly.
Adobe Experience Manager Help | Common Repository Restructuring in AEM 6.4
Previous location | /etc/designs/default |
New location(s) | /libs/settings/wcm/designs/default /apps/settings/wcm/designs/default |
Restructuring guidance | For any Designs that are managed in SCM, and not written to at run-time via Design Dialogs.
|
Notes | N/A |
Views
Replies
Total Likes
Hi,
the best approach is to create the apps version and then use the API as described by gauravb10066713.
If you want to know how to use the sling model in order to get some values into a specific path, this is the snippet that you could use:
@Model(adaptables=SlingHttpServletRequest.class)
public class GetResourceFromPathModel {
private static final Logger LOG = LoggerFactory.getLogger(GetResourceFromPathModel.class);
private static final String SERVICENAME = "GETRESOURCESERVICE";
@Inject
private ResourceResolverFactory resourceResolverFactory;@PostConstruct
protected void init() {
ResourceResolver resourceResolver = getResourceResolverBySystemUser(resourceResolverFactory);
Resource linksResource = resourceResolver.getResource("/libs/settings/wcm/designs/default/jcr:content/main/content/links");
//linksResource.adaptTo(Node.class).getProperties();
//or
//linksResource.adaptTo(ValueMap.class)
}private ResourceResolver getResourceResolverBySystemUser(ResourceResolverFactory resourceResolverFactory) {
Map<String, Object> param = new HashMap<String, Object>();
param.put("sling.service.subservice", SERVICENAME);
ResourceResolver resolver = null;
try {
resolver = resourceResolverFactory.getAdministrativeResourceResolver(param);
} catch (LoginException e) {
LOG.error("getResourceResolverBySystemUser: Unable to retrieve resource resolver" , e);
}
return resolver;
}
}
Hi,
if you use the design dialog, why don't you use the Designer API, which abstracts this for you.
For example: Design ("The Adobe AEM Quickstart and Web Application.")
(seems that there is some issue with the AEM 6.4 javadoc for this class; I just verified that the API still exists as of AEM 6.4, so you can use it.)
For long-term stability, I would recommend you to consider the new Style system, which is the new way to build templates and components (combined with Editable templates).
Views
Like
Replies