Expand my Community achievements bar.

Sling API in AEM | AEM Community Blog Seeding

Avatar

Administrator

2/6/23

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.

1 Comment