Standard site layout xml

Andy Wardley abw at wardley.org
Wed Mar 12 08:40:39 GMT 2008


Mark Knoop wrote:
> I am looking at TT to supercede the templating side of things but I 
> wondered is there a standard site-generator-layout format/interpreter 
> that I can use for the site layout which has already dealt with all the 
> variations I keep running into and having to hack?

The usual approach is to have one (or more) master layout templates which
you define using the WRAPPER option.  A simple layout template might look
something like this:

    <html>
      <head>
        <title>[% template.title %]</title>
      </head>
      <body>
        [% PROCESS header %]
        [% content %]               <--- page output goes here
        [% PROCESS footer %]
     </body>
   </html>

Each page template is processed and the output inserted into the 'content'
slot of the layout template. So your page template might look like this:

   [% META title="Hello World" %]
   Badger Badger Badger Mushroom!

And the output would be:

    <html>
      <head>
        <title>Hello World</title>
      </head>
      <body>
        (output from header)
        Badger Badger Badger Mushroom!
        (output from footer)
     </body>
   </html>

Because your layout template is just a regular old TT template, you can
include any kind of presentation logic in there that takes your fancy,
e.g. [% INCLUDE extra_menu IF some_condition %]

HTH
A


BTW: you might find the templates mailing list to be a better place for these 
kind of questions: http://mail.template-toolkit.org/mailman/listinfo/templates


More information about the london.pm mailing list