Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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:

Code Block
languagehtml/xml
#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-INF/lib. The SiteMesh distribution comes with velocity-dep-1.3.1.jar.

Download VelocityTools 2.0 and copy it into 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-INF/lib. The SiteMesh distribution comes with commons-collections.jar.

Add the following to WEB-INF/web.xml within the <web-app> tag:

Code Block
languagehtml/xml
<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 source code 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