April 24, 2020
Estimated Post Reading Time ~

The AEM – Sling connection simplified

Apache Sling is a web framework based on the JCR API. We have seen that the content in AEM is saved as nodes and properties in Oak – reference implementation of JCR. In most simple terms, Sling, in AEM’s context, helps you to issue http requests and render content from Oak repository appropriately.

Use Template Sling Sample.zip from my GitHub account.




Sling uses scripts or servlets to render content. Sling uses the node’s sling:resourceType property to determine the script that renders the content. Let us see what happens when you access a url.

Assume that you access the following url: http://localhost:4502/content/aem-company.html. First, the request goes to /content/aem-company. The node has a sling:resourceType property that points to aem-company/components/homepage. Here Sling gets the location of the script or servlet that needs to be used to render the content. It checks for the location in the apps folder and locates the node. And, then render the content based on the default script, body.html. I have explained how body.html becomes the default script in one of the previous posts. Have a look at that.

We changed the url by adding test.html which specifies the default script that needs to be used to render the content. (It’s called a selector.) In this way, you can manipulate the url and provide content accordingly. For example, using the same url, but different selectors, like product.html and product.details.html you can provide different and meaningful content.
See that the page is rendered. In the same location, I mentioned above (/apps/aem-company/components/homepage), Sling searches for details.html, obviously couldn’t find it. It then used details.jsp to render the content.

This kind of script resolution mechanism Sling uses is important for you to know. See a cheat sheet Adobe prepared: http://dev.day.com/content/ddc/blog/2008/07/cheatsheet.html
Take a look at this page – there are plenty of information. I hope you got a general idea about Sling now. Consider it as a starting point & happy learning.

See you soon.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.