SiteMeshStringTemplateDecorators - danielbodart/webfabric GitHub Wiki

SiteMesh 2 ships with support for a number of different templating languages but not StringTemplate.

SiteMesh 3 is now supported

Here is an example of what a decorator in StringTemplate (e.g. /decorators/example.st) might look:

Example Decorator

<html>
<head>
    <title>company.com : $title$</title>
    $head$
</head>
<body>
    <div class="header">
        <h1>$title$</h1>
    </div>
    <div class="contents">
        $body$
    </div>
    <div class="footer">
        Copyleft company.com
    </div>
</body>
</html>

Installation

The current version has been tested with the following jars (older versions should work)

  • stringtemplate.jar (3.2) and therefore antlr-2.7.7.jar

  • sitemesh-2.4.2.jar or sitemesh-3.0.0-SNAPSHOT.jar

  • scala-library.jar (2.7.7)

Add the following to [web-app]/WEB-INF/web.xml within the web-app tag:

    <servlet>
        <servlet-name>sitemesh-stringtemplate</servlet-name>
        <servlet-class>org.webfabric.sitemesh.StringTemplateDecoratorServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>sitemesh-stringtemplate</servlet-name>
        <url-pattern>*.st</url-pattern>
    </servlet-mapping>

Attributes

The following attributes are available in your templates

$base$ HttpServletRequest.getContextPath()

$query$ ServletRequest.getParameterMap()

$title$ Parsed page title

$head$ Parsed page head

$body$ Parsed page body

$properties$ A map of properties (sub properties can accessed directly $properties.div.id$)

$include$ Allows you to do server side includes.

For example $include.("http://www.google.co.uk").body$ would include the body of the google homepage. include.(url) will return a HTMLPage so all the normal properties are available. Also supports absolute paths resolved against the request.getContextPath()

⚠️ **GitHub.com Fallback** ⚠️