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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.