Re: header + footer templates for sub-pages

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
The usual way of doing that is with macros. Like, you could have an
ftl file that holds all the macros that are commonly used in your
application, and one one them could be "page". Something like this:

--- lib/commons.ftl ---
...
<#escape x as x?html>
...
<#macro page title>
  <html>
    <head>
      <title>${title}</title>
    </head>
    <h1>${title}</h1>

    <#nested>

    <hr>
    <p>Copyright blah blah...</p>
  </html>
</#macro>
...
</#escape>
------

--- sometemplate.ftl ---
<#import "/lib/commons.ftl" as c>
<@c.page "Something">
  ... your page-specific content goes here ...
</@c.page>
------

If you want to avoid the #import statement, then you could use
auto-imports (see in the Configuration class API), however that can
make understanding the templates harder for other people, or even for
you a year later.

-- 
Best regards,
 Daniel Dekany

Saturday, July 3, 2010, 4:04:46 PM, S Ahmed wrote:

> I want all my sub-pages to have a header + footer in them, without
> having to put a header + footer in each and every view page.
>
> The idea is that I can edit a single main template to edit the
> header and footer, and the rest of the pages will be modified.
>
> Is this possible?
>
> Main Template will have:
>
> Header
> <<Content>>
> Footer
>
>
> Then each sub-page will inherit from the 'Main Template' and then
> my sub-pages will only have to inject contents for the <<content>> area.
>
> Is this possible?


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.