Sling API in AEM | AEM Community Blog Seeding | Community
Skip to main content
kautuk_sahni
Community Manager
Community Manager
February 7, 2023

Sling API in AEM | AEM Community Blog Seeding

  • February 7, 2023
  • 1 reply
  • 1095 views

BlogImage.jpg

Sling API in AEM by v karthick

Abstract

The Sling API provides a wide range of functionality for interacting with the content repository, so the examples will vary depending on what specific tasks you want to perform.

However, I can provide some examples that demonstrate common use cases of the Sling api with respect AEM.

Creating a node:
ResourceResolver resourceResolver = ...;
Resource resource = resourceResolver.getResource("/content");
ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);
properties.put("propertyName", "propertyValue");
resourceResolver.commit();
2. Reading a node:

ResourceResolver resourceResolver = ...;
Resource resource = resourceResolver.getResource("/content/newNode");
if (resource != null) {
ValueMap properties = resource.getValueMap();
String propertyValue = properties.get("propertyName", String.class);
}
3. Updating a node:

ResourceResolver resourceResolver = ...;
Resource resource = resourceResolver.getResource("/content/newNode");
if (resource != null) {
ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);
properties.put("propertyName", "newPropertyValue");
resourceResolver.commit();
}

Read Full Blog

Sling API in AEM

Q&A

Please use this thread to ask the related questions.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Level 3
February 16, 2023

Note you can also make use of the JCR API, in addition to the Sling API. 

https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/access-jcr.html?lang=en