I don't know how invested you are in HTML::Template, if you're pretty heavy into it than you can probabbly ignore the rest of this post. Fyi I think the only real way to do this with HTML::TEmplate is the first method you specified.
Stuff like this is one of the main reasons I ended up switching from HTML::Template to Template::Toolkit. With template toolkit you can do something like
[% # THis is in templatelib.tt %]
[% MACRO date_template(parm1, parm2, parm3) BLOCK %]
[% SWITCH parm1 %]
[% CASE "value 1" %]
display this way
[% CASE "value 2" %]
display other way
[% CASE DEFAULT %]
display default way
[% END %]
[% END %]
Your main template could look something like
[% # this is foo.tt %]
[% PROCESS templatelib.tt %]
[% date_template(parm_from_script, "foo", "bar") %]
your perl would look something like
my $template = Template->new();
my $t_vars = {
parm_from_script => "value 1",
other_stuff => "mmmm donuts",
};
$template->process("foo.tt", $t_vars) ||
die $template->error();
Granted, there is now "code" inside the html, but it's still all display logic. It's not the processing logic. I tend to make the line between perl/templates in that perl will handle anything that's not strictly for display while the templates will handle everything else. People disagree with this and they're right too. :P
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.