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.


In reply to Re: CGI within your layout by Tanktalus
in thread CGI within your layout by Anonymous Monk

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.