I too am using SiteMesh to decorate my FreeMarker views. Here's how I worked around the problem:
1. Defined these two Freemarker macros (my macros file is called Macros.ftl, but you could use any name):
Code:
<#-- Gets the value of the specified meta tag, or an empty string if it's not set -->
<#macro meta name>
<#assign key="meta." + name/>
<#assign value=page.properties[key]?default("")/>${value}</#macro>
<#-- Adds HTML meta tags containing the Strings needed by the layout page -->
<#macro metadata>
<meta name="some.key" content="${some_FTL_expression}"/>
<meta name="some.other.key" content="<@spring.message code="some_Message_Code"/>"/>
<meta name="yet.another.key" content="<@macros someOtherMacro/>"/>
<#-- other values as needed -->
</#macro>
3. Each of my view templates starts by invoking the "metadata" macro:
Code:
<#import "/spring.ftl" as spring />
<#import "/Macros.ftl" as macros />
<@macros.metadata/>
<#-- Rest of template goes here -->
This causes each view to read the values/expressions listed in the "metadata" macro and output them as HTML <meta> tags. In my case, these values are things like locale-sensitive messages, the username, my company name, and the name and version of my application
4. Then in my layout template (the one used by SiteMesh to perform the decoration), I read each of those HTML meta tags where necessary using the first macro, e.g.:
Code:
<#import "/Macros.ftl" as macros />
<p><@macros.meta name="some.other.key"/></p>
which at runtime generates the following HTML snippet:
Code:
<p>Hello World!</p>
Where "Hello World!" was the resource bundle translation of the "some_Message_Code" message code. The downside of this solution is that I have to edit the "metadata" macro every time I add a new piece of text to the layout template. If you come across a neater solution, please let me know!