I've got a large CGI-based application which is in need of a graphical overhaul, only I've run into a snag working out how to do that.

Right now I've got a large collection of HTML::Template files which make up the site, with each "page" of the site coming from a distinct template. Each template contains basically the page-specific stuff and the actual layout code. The latter I'd like to abstract away to make a site redesign more feasible.

(I do use file inclusion to include a common header and footer, but that is about the extent of the consistency and abstraction.)

My initial plan was to split up the site such that each template would only contain the "body" of the output - and have a global template which would define the layout information. To that end I've written a simple test program:

#!/usr/bin/perl -w use strict; use warnings; use HTML::Template; # # Load the layout and a stub page of "content" # my $layout = HTML::Template->new( filename => "./layout.template" ); my $page = HTML::Template->new( filename => "./page.inc" ); # # Insert the body into the layout template # $layout->param( page => $page->output() ); # # Now setup the title # $layout->param( title => "STEVE" ); print $layout->output();

Unfortunately this doesn't work as expected because the nested expansion of the $title in the body template fails to occur.

Does anybody have suggestions on how I could fix this? Or a better idea on how to keep a consistent and maintainable site design over a number of templates?

For reference here are the templates - as you can see I'm trying to only need to setup the $title expansion once, and have it apply to both the "layout" and the "body":

layout.tmpl

<html> <head> <title><!-- tmpl_var name='title' --></title> </head> <body> <!-- tmpl_var name='page' --> </body> </html>

page.inc:

<h2><!-- tmpl_var name='title' --></h2> <p>Imagine content here ..</p>
Steve
--

In reply to 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.