I may be missing something here, but this seems to work, at the price of (partially) re-mixing content and layout. Further, from the description of your project, I'm guessing that you will be taking the title from the command line or yet another file, hence the new var, $input.
#!/usr/bin/perl -w # 655823 use strict; use warnings; use HTML::Template; # new; replace to use from ARGV or some other project file my $input = "STEVE"; my $layout = HTML::Template->new( filename => "layout.tmpl" ); my $page = HTML::Template->new( filename => "page.inc" ); $layout->param( page => $page->output() ); # Now setup title with $input, rather than hardcoding $layout->param( title => "$input" ); # spit out the page print $layout->output();
When layout.tmpl is modified by moving the line <h2>...</h2> from page.inc, to line 6 here:
<html> <head> <title><!-- tmpl_var name='title' --></title> </head> <body> <h2><!-- tmpl_var name='title' --></h2> <!-- tmpl_var name='page' --> </body> </html>
after which, page.inc becomes simply
<p>Imagine content here ..</p>and the output is:
<html> <head> <title>STEVE</title> </head> <body> <h2>STEVE</h2> <p>Imagine content here ..</p> </body> </html>
This leaves various issues, however; the most obvious being any case in which your page.inc was more complex -- eg, has body content intended to appear before the <h2...> pair. That's because this writer tackled the question only to begin acquiring more than my current, mimimal knowledge of HTML::Template.
In reply to Re: Abstracting away layout details when using large HTML::Template-based sites?
by ww
in thread Abstracting away layout details when using large HTML::Template-based sites?
by skx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |