microsling Velocity templates

back to homepage

When processing requests, the VelocityTemplatesServlet ask the SlingScriptResolver for scripts with the .vlt extension.

If a script is found, it used as a Velocity template to render the content.

To test this, try storing (via WebDAV, see mount point URL on the microsling homepage) the following script in your repository under /sling/scripts/microsling/example/html.vlt . Doing so will cause microsling to use that script to render nodes having slingResourceType=microsling/example.

To try that rendering, use the content creation page to create and node and display it.

The name html.vlt indicates that this script is meant to process HTTP GET requests with expect a text/html response.

For other HTTP methods the script would have the method name, for example POST.vlt for a POST. But GET is probably the only request method that makes sense to process with Velocity templates.

To generate XML instead, rename the script to xml.vlt, modify it to generate the XML of your choice, and replace .html with .xml at the end of the request URL.

Here's the example HTML template. See the Velocity website for more info about the syntax.

<html>
<body>
<h1>This is generated from a Velocity template</h1>
<p>
  The current resource URI is <b>$resource.URI</b>
</p>

<h2>$resource.getItem().getProperty("title").getString()</h2>
<p>
  $resource.getItem().getProperty("text").getString()
</p>

</body>
</html>

To deactivate the Velocity-based rendering of nodes, rename or delete the corresponding rendering scripts.