http://www.perlmonks.org?node_id=655823

skx has asked for the wisdom of the Perl Monks concerning the following question:

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
--