A possibly non-obvious "other means" is to produce the table HTML by using a separate HTML::Template instance that uses its own template for the table part. This looks like
sub tableHTML { my %table_data = @_; my $template = HTML::Template->new(filename => 'table.tmpl'); $template->param(%table_data); return $template->output; }
You now have the basis for a reusable component that you can pull out any time you need to embed tables in a template. Variations include passing a query into the component, which then extracts data from some data source. This technique also extends nicely to other types of components.

One thing that concerns me about this approach is that you now have to worry about managing a template widget library. Either you copy table.tmpl into every project directory that needs it, or you introduce some scheme for looking these widgets up every time they're referenced -- and doing version control ala "DLL Hell". (There may be a third way that escapes me at the moment; I suppose you could symlink to table.tmpl every time you need it, but that seems to me like the worst of both worlds.)

This is hardly an insurmountable problem, but I don't think it's trivial, either. (Maybe I'm wrong; if so, would someone point me to the trivial solution please? :-) So it seems to me that this "template widgets" approach would be more useful for a large, relatively heavyweight project than for something smaller... and my point of view is no doubt coloured by the fact that I'm mostly interested in smaller projects.

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
% man 3 strfry


In reply to Re: Reusable template components with HTML::Template by FoxtrotUniform
in thread Reusable template components with HTML::Template by dws

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.