Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

header and footer and freemarker

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.

like image 587
Blankman Avatar asked Jul 01 '10 03:07

Blankman


3 Answers

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>
like image 71
Jiří Vypědřík Avatar answered Oct 21 '22 21:10

Jiří Vypědřík


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)

like image 31
Sean Patrick Floyd Avatar answered Oct 21 '22 23:10

Sean Patrick Floyd


Have a look at SiteMesh. I believe you will find it useful.

like image 1
Eric Adamson Avatar answered Oct 21 '22 21:10

Eric Adamson