Velocity Decorators

As of SiteMesh 2.0.2 Velocity (.vm) decorators are supported.

Here is an example of how such a decorator (e.g. /decorators/main.vm) might look like:

    #parse ("/includes/decorators/header.vm")
        <h2>$title</h2>
        $head
        <img src="$base/images/logo.gif" border="0">
        <td valign="top" class="body">
            <div class="header">
                <span class="pagetitle">$title</span>
            </div>
            $body
        </td>
    #parse ("/includes/decorators/footer.vm")

### Installation

- Download Velocity 1.3.1 or higher and copy it into `[web-app]/WEB-INF/lib`. The SiteMesh distribution comes with velocity-dep-1.3.1.jar.
- Download VelocityTools 1.1 and copy it into `[web-app]/WEB-INF/lib`. The SiteMesh distribution comes with velocity-tools-view-1.1.jar.
- Download Commons Collections 2.1 or higher and copy it into `[web-app]/WEB-INF/lib`. The SiteMesh distribution comes with commons-collections.jar.
- Add the following to `[web-app]/WEB-INF/web.xml` within the `<web-app>` tag:

    <servlet>
        <servlet-name>sitemesh-velocity</servlet-name>
        <servlet-class>com.opensymphony.module.sitemesh.velocity.VelocityDecoratorServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>sitemesh-velocity</servlet-name>
        <url-pattern>*.vm</url-pattern>
    </servlet-mapping>

- Modify `decorators.xml` to reference a .vm decorator.

A working example is included with the SiteMesh distribution, under the src/example-webapp directory.

### Context

VelocityDecoratorServlet puts some things into the context object that you should be aware of:

$request (from VelocityViewServlet) | The HttpServletRequest object
$response (from VelocityViewServlet) | The HttpServletResponse object
$session (from VelocityViewServlet) | The HttpSession object
$application (from VelocityViewServlet) | The ServletContext object
$base | request.getContextPath()
$title | Parsed page title (<title>...<title>)
$head | Parsed page head
$body | Parsed page body
$page | SiteMesh's internal Page object
Anything else | Search for the attribute by that name in the request, session and application scopes