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.
Define a macro like this in an import library:
<#macro page title>
<html><head><title>${title?html}</title></head>
<body>
<!-- header section -->
<#nested/>
<!-- footer section -->
</body></html>
</#macro>
and use the following template for all your pages:
<#import "common.ftl" as c/>
<@c.page title="custom page title">
<!-- custom page content -->
</@c.page>
You can find the spring-specific part in the spring reference and the freemarker part in the freemarker online docs
(It doesn't seem like Freemarker supports master pages, but through recursive use of include
you can achieve a high level of code reuse)
Have a look at SiteMesh. I believe you will find it useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With