in reply to CGI within your layout

There may be more than one way to do it, but there's also more than one way to think about (doing) it.

sub display_template { my %opts = @_; my $output; my $files = $opts{file}; my @files = ref $files ? @$files : ($files); unless ($opts{no_header} or $opts{bare}) { my $header = $opts{header} || 'header.tmpl'; my $tmpl = HTML::Template->new($header); $tmpl->param(...); # common params $tmpl->param(%{$opts{header_param}}) if $opts{header_param}; $output .= $tmpl->output(); } foreach my $file (@files) { my $tmpl = HTML::Template->new($file); $tmpl->param(...); # common params $tmpl->param(%{$opts{params}}) if $opts{params}; $output .= $tmpl->output(); } unless ($opts{no_footer} or $opts{bare}) { my $footer = $opts{footer} || 'footer.tmpl'; my $tmpl = HTML::Template->new($footer); $tmpl->param(...); # common params $tmpl->param(%{$opts{footer_param}}) if $opts{footer_param}; $output .= $tmpl->output(); } $output; }

That's pretty close to what I use for mine. As you can see, it takes named parameters - things like "file" which can take either a single file name, or an arrayref of filenames, or 'header' to name the header file (defaults to 'header.tmpl'), or 'no_header' to remove the header altogether, or 'bare' to remove both header and footer at the same time. Then there's 'header_param' which is a hashref of parameters to pass in to HTML::Template for the header, similarly for the main files and the footer. And then, it returns the whole thing - because I use CGI::Application, and that's the way C::A works.

Hope that helps.