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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.