Locate content resource
Resource path is used to locate content resource
- Sling checks weather a node exists at the location specified in the request(e.g. /content/articles/category-name/article-name.print.a4.html)
- If no node is found ,the the extension is dropped and search repeated (e.g. /content/articles/category-name/article-name.print.a4)
- If no node is found then return 404 http code
Locate scripts once content resource is located
- The sling:resourceType is used to locate script to be used for rendering the content.
- Scripts are located in /apps or /libs.
- If certain rest method(GET, POST) is required, it should be specified in upercase within script name(e,g. a4.POST.jsp).
- If multiple scripts apply for a given request
The script with the best match is selected. The more specific a match is ,the better it is; in other word, the more selector matched the better, regardless of any request extension or method name match.
Rules:
- Folder(e.g. nodes of tyope nt:folder) takes precedence over jsp file names when resolving using selectors, at least the first selector.
- Only one selector in a file name has effect, any file name contains two selectors don’t ever get selected, but name of folder can be used to match the selector in the request.
- Scripts with HTTP method names(e.g. GET.jsp) is selected as a last resort even after the default script(examples.jsp)
- The precedence of same name files are html > jsp > esp. E.g. if examples.html and examples .jsp both exist,then the examples.html will be shown.
For example: http://www.aemtreasury.com/content/resolution.print.a4.html/a/b?name=Dale of type sling:resourceType=”dale/example”
Assuming scripts structure as diagram below:
The order of preference should be as shown:
- /apps/dale/example/print/a4.html.jsp
- /apps/dale/example/print/a4/html.jsp
- /apps/dale/example/print/a4.jsp
- /apps/dale/example/print.html.jsp
- /apps/dale/example/print.jsp
- /apps/dale/example/html.jsp
- /apps/dale/example/example.jsp
- /apps/dale/example/GET.jsp
I prefer to make the script name is the same with fold name which is easy to remember, in this case is /dale/example/example.jsp
Note
- Supported script engines are list at http://localhost:4502/system/console/status-slingscripting (menu: Status>>>Script Engines). Sling can integrate with other script engines, e.g. Groovy
- Sling scripts should not be called directly.
- sling:resourceSuperType: Super types are also considered when trying to find a script. The advantage of resource super types is that they may form a hierarchy of resources where the default resource type sling/servlet/default (used by the default servlets) is effectively the root. (https://docs.adobe.com/docs/en/aem/6-0/develop/the-basics.html).