12

My website has a consistant header and footer that I want on all pages.

What is the best way to do this?

The header will have some dynamic data also, based on the current view.

P.S Does freemarker have any sort of master page functionality? Where I can create a base template, then have other templates build upon the base?

Basically I want to design a template that has header and footer + a place holder for the main content area. THEN, all other pages will inherit the main template (with header + footer), and then inject the action's render output into the templates main content area.

4

3 回答 3

17

在导入库中定义这样的宏:

<#macro page title>
    <html><head><title>${title?html}</title></head>
    <body>
    <!-- header section -->
    <#nested/>
    <!-- footer section -->
    </body></html>
</#macro>

并为您的所有页面使用以下模板:

<#import "common.ftl" as c/>
<@c.page title="custom page title">
    <!-- custom page content -->
</@c.page>
于 2011-06-19T09:13:52.710 回答
1

看看SiteMesh。我相信你会发现它很有用。

于 2010-12-17T09:32:04.243 回答
1

您可以在 spring 参考中找到 spring 特定部分,在 freemarker 在线文档中找到freemarker 部分

(貌似Freemarker不支持母版页,但是通过递归使用include可以实现高水平的代码复用)

于 2010-07-01T08:43:00.827 回答