# Screen/Common.pm
#----------------------------
sub header {
my ($class,$title) = @_;
my $t = HTML::Template->(filename => 'header.t');
...
return $t->output;
}
sub menu {
my ($class,$items) = @_;
my $t = HTML::Template->new(filename => 'menu.t');
...
return $t->output;
}
sub footer {
my $t = HTML::Template->new(filename => 'footer');
....
return $t->output;
}
## app.cgi
##----------------------------
#!/usr/bin/perl
use Screen::Common
my $common = Screen::Common->new;
print $common->header("My Title");
print $common->menu({item1 => 'Text',...});
....body output
print $common->footer;
-Carlos
P.S. This is my second attempt at posting this message, hopefully this is not a duplicate.
Drew Taylor wrote:
Hi,
I would like to automatically wrap a template in a header and footer without having to specify <TMPL_INCLUDE [header|footer].tmpl> for every page. In TT I can use the PRE_PROCESS and POST_PROCESS options, which specify a template that is pre/appended to the specified template. Is there an easy way to automatically do this in HTML::Template?
It looks like I can do this with a filter, but it doesn't feel right to me.
my $filter = sub {
my $text = shift;
unshift @$text, "<TMPL_INCLUDE header.tmpl>";
push @$text, "<TMPL_INCLUDE footer.tmpl>";
}
my $template = HTML::Template->new('file.tmpl',filter=>{sub=>$filter,format=>'array'});
Drew
--
Drew Taylor | Web development & consulting
http://www.drewtaylor.com/ | perl/mod_perl/DBI/mysql/postgres
----------------------------------------------------------------------
"If you don't know what your program is supposed to do,
you'd better not start writing it." -Edsger Dijkstra
----------------------------------------------------------------------
Speakeasy.net DSL - http://www.speakeasy.net/refer/29655
-------------------------------------------------------
This sf.net email is sponsored by: Are you worried about your web server security? Click here for a FREE Thawte Apache SSL Guide and answer your Apache SSL security needs: http://www.gothawte.com/rd523.html
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users
-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing your web site with SSL, click here to get a FREE TRIAL of a Thawte Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users
