John Wang wrote:
> If I want to separate out my header/footer/navigation elements is it better
> to break those into two to three different templates and INCLUDE them or put
> all of the elements into one template and use WRAPPER? I think WRAPPER is
> cleaner but I'm not sure if there is a performance hit doing it that way.
> Will caching work just as well both ways?

I tend to use multiple wrappers.  My WRAPPER option will be set something
like this:

  WRAPPER => site/wrapper

The template looks something like this:

[% SWITCH template.type;
     CASE 'text';
       content;

     CASE;
       content WRAPPER site/html
                     + site/layout;
   END
%]

In my template I can set [% META type='text' %] if I don't want the 
standard html layout wrapper(s) added (e.g. for CSS and Javascript 
files).  

Otherwise the site/html and site/layout wrappers get applied.
They usually look something like this:

site/html:

  <html>
   <head>
    <title>[% template.title %]</title>
    ...etc..
   </head>

   <body>
   [% content %]
   </body>
  </html>

site/layout:

  [% PROCESS site/header
           + site/body
           + site/footer 
  %]

Depending on how complicated the site layout is, site/body may break
down further into a sidebar, main page area, menus, and so on.  

site/header:
  <div id="header">
   # header markup
  </div>

site/body:
  <div id="body">
    [% PROCESS site/sidebar
             + site/navbar
    %]
    <div id="content">
     [% content %]
    </div>
  </div>

site/footer:
  <div id="footer">
   # footer markup
  </div>

I tend to follow the one-element-per-template rule where possible.  The 
site/header template defines the <div id="header">...</div> element, 
site/sidebar defines the <div id="sidebar>...</div> element, and so on.  

I find it helps to break down complex, nested markup like this so you can 
get a clearer picture of how the site is built up.  It's also useful in 
debugging because the <div> and </div> tags delimit the start and end of
each template and the div id usually corresponds to the template name.

Now, if you're building static HTML pages offline using ttree or some 
other tool, then the performance hit of processing extra templates really
shouldn't matter.  However, if you're dynamically generating pages online
and you're concerned about server load or response times, then you can 
optimise the above into a single template.

Create a source file like this:

  [% TAGS star %]
  [* META title="[% template.title %]" *] 
  [% content %] 

Then run it through the above wrappers, and you'll end up with an output
file that looks something like this:

  <html>
   <head>
     <title>[% template.title %]</title>             
     # etc
   </head>

   <body>
     # lots of complicated markup
   [% content %]                                      
     # more complicated markup
   </body>
  </html>

Voila!  You have a single template skin which you can use as the WRAPPER 
on your live server.  If you need to change anything then you still have 
the nicely organised, multiple template setup described above.  Make your 
changes, regenerate the skin, and you're done.  

HTH
A


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to