in reply to Re: Re: HTML::Template - complex sites
in thread HTML::Template
Now, that was just an example ... i don't always use that format, but i hope you get the picture. The idea is that you break up the "elements" of the web site into their own files. Say you have a menu bar on the side. You can abstract the HTML into it's own file and then simply include that file when you need it. As long as code that populates the params of the HTML::Template object passes the parameters that 'widget' needs, all is well. Here is a complete example you can play with:<html> <head> <title><tmpl_var title></title> </head> <body> <tmpl_include name="header.html"> <tmpl_var CONTENT> <tmpl_include name="footer.html"> </body> </html>
The skeleton template:#!/usr/bin/perl -T use strict; use warnings; use CGI qw(header); use HTML::Template; my $tmpl = HTML::Template->new(filename => 'skeleton.tmpl'); $tmpl->param( title => "I AM JACK's HTML TITLE", CONTENT => "I AM JACK's HTML CONTENT", menu => [ {item => "JACK's LIVER", url => 'liver.html'}, {item => "JACK's SPLEEN", url => 'spleen.html'}, {item => "JACK's SPRAT", url => 'sprat.html'}, ], ); print header, $tmpl->output;
The header template:<html> <head> <title><tmpl_var title></title> </head> <body> <tmpl_include header.tmpl> <tmpl_var CONTENT> <tmpl_include footer.tmpl> </body> </html>
The footer template:<h1>hello world</h2> <tmpl_include menu.tmpl>
And finally, the menu template:<h1>goodbye world</h1>
<ol> <tmpl_loop menu> <li><a href="<tmpl_var url>"><tmpl_var item></a></li> </tmpl_loop menu> </ol>
Oh, and remember, sometimes it is more trouble than it is worth to get as abstract as you possible can. You might wind up making your interface so general that no one can easily use it anymore. :/
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|