Sling Scripting

Sling Scripting Engines

Sling Scripting is build around Java Scripting API (JSR 223). It allows the easy development and usage of different scripting (aka templating) engines.

The script engines are managed in SlingScriptEngineManager (Scripting Core).

Engine Language Name Language Version Names Extensions Mime Types GitHub Repo(s) Documentation
FreeMarker FreeMarker freemarker.template.Configuration#getVersion().toString() FreeMarker
freemarker
(configurable)
ftl
(configurable)
text/x-freemarker
(configurable)
sling-org-apache-sling-scripting-freemarker
Groovy (GString) Groovy GString org.codehaus.groovy.util.ReleaseInfo#getVersion() GString
gstring
(configurable)
gst
(configurable)
(configurable) sling-org-apache-sling-scripting-groovy
HTL The HTL Templating Language 1.4 htl
HTL
sightly
html sling-org-apache-sling-scripting-sightly Scripting HTL
Java Java Servlet Compiler 1.5 java
Java
java sling-org-apache-sling-scripting-java
JavaScript ECMAScript partial ECMAScript 2015 support rhino
Rhino
javascript
JavaScript
ecmascript
ECMAScript
esp
ecma
text/ecmascript
text/javascript
application/ecmascript
application/javascript
sling-org-apache-sling-scripting-javascript
JSP Java Server Pages 2.1 jsp
JSP
jsp
jspf
jspx
sling-org-apache-sling-scripting-jsp Scripting JSP
Thymeleaf Thymeleaf version from /org/thymeleaf/thymeleaf.properties Thymeleaf
thymeleaf
(configurable)
html
(configurable)
text/html
(configurable)
sling-org-apache-sling-scripting-thymeleaf Scripting Thymeleaf

Several more engines are available but experimental or no longer maintained:

  • ESX
  • JST
  • Python
  • Ruby
  • Scala
  • Velocity
  • XProc

Code for really old modules might be found in the svn attic.

Mapping script extensions to engines

Since version 2.0.60 Scripting Core supports the mapping of extensions to engines in content (SLING-4330).

This is required when registering more than one script engine for a single script extension (e.g. using HTL for vendor-related scripts in /libs and Thymeleaf for project-related scripts in /apps, both using extension html).

It works by adding a sling:scripting property to the script resource or a resource in the hierarchy above the script (e.g. project or parent folder).

The mapping consists of a key which is the script extension and a value which itself could consist of four values separated by colon to identify the script engine:

  1. language name (required)
  2. language version (optional)
  3. engine name (not used yet)
  4. engine version (not used yet)

The sling:scripting property supports multiple mappings for different extensions (e.g. html and js).

In case there is more than one script engine for a script extension registered and no mapping is found the script engine with higher service ranking gets used for rendering.

Sample mappings

Mapping html to HTL 1.4:

"sling:scripting": [
  "html=The HTL Templating Language:1.4"
]

Mapping html to Thymeleaf 3.0:

"sling:scripting": [
  "html=Thymeleaf:3.0"
]

Scripting variables

See also Scripting variables and Adding New Scripting Variables.