Here is an example of how such a decorator might look like:
<#include "/includes/decorators/header.dec"> <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> <#include "/includes/decorators/footer.dec">
[web-app]/WEB-INF/lib
.
The SiteMesh distribution comes with freemarker.jar v2.3rc3[web-app]/WEB-INF/web.xml
within the <web-app>
tag:<servlet> <servlet-name>sitemesh-freemarker</servlet-name> <servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class> <init-param> <param-name>TemplatePath</param-name> <param-value>/</param-value> </init-param> <init-param> <param-name>default_encoding</param-name> <param-value>ISO-8859-1</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>sitemesh-freemarker</servlet-name> <url-pattern>*.dec</url-pattern> </servlet-mapping>
decorators.xml
to reference a .dec file.<#include "/includes/decorators/header.dec"> <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> <#include "/includes/decorators/footer.dec">
FreemarkerDecoratorServlet puts some things into the context object that you should be aware of:
${Session["user"]}
<#assign ww=JspTaglibs["/WEB-INF/webwork.tld"]>
<#assign ww=JspTaglibs["/WEB-INF/webwork.tld"]> ... <@ww.property value="myVar"/>
base | request.getContextPath() |
title | Parsed page title (<title>...<title>) |
head | Parsed page head |
body | Parsed page body |
page | SiteMesh's internal Page object |