modulereview
defyance
We hear about it all the time, and most, if not all of us have dabbled in it at one time. You know what I speak of, Dynamic web content. Well, if you prefer, or are required to use a template system, might I suggest giving HTML::Template a go. Some may ask my main reason for endorsing it, to which I would respond with simplicity, and flexibility. Hands down, HTML::Template gotta be the simplest way to manage templates. Lets give an example.
<p />
Taken from the CPAN docs [cpan://HTML::Template]:
<p />
Create a simple HTML page, with two template variables <code>HOME</code> and <code>PATH</code>, name it test.tmpl.
<br />We will fill the variables with data <a href="#CODE">below</a>.
<code>
<html>
<head><title>Test Template</title>
<body>
My Home Directory is <TMPL_VAR NAME=HOME>
<p>
My Path is set to <TMPL_VAR NAME=PATH>
</body>
</html>
</code>
<p />
Now, lets build a program to fill in those previously named variables. The result is displayed <a href="#OUT">below</a>
<a name="CODE"></a><code>
#!/usr/bin/perl -w
use HTML::Template;
# open the html template
my $template = HTML::Template->new(filename => 'test.tmpl');
# fill in some parameters
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});
# send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n", $template->output;
</code>
<p />
<a name="OUT"></a>
Make sure its all ready to go, then point your browser to the script you just created, now, you should have output that looks kinda like this:
<p />
<code>
My Home Directory is /home/some/directory
My Path is set to /bin;/usr/bin
</code>
Simple, no?
<p>
<strong>It Gets Better</strong>
<p />
Not only does it support simple variables, you can also:
<p />
<li />Escape HTML from your data!
<li />Set default values, if data is not supplied by param!
<li />Build Loops!
<li />Include other templates!
<li />Build Conditionals!
<li />Error handling has descriptive error output, which speeds up debugging!
<li />And much more!
<p />
I'm not going into much more detail here, I like to keep it simple, just know that I have found it useful. Paired with [cpan://CGI], [cpan://DBD::mysql], [cpan://CGI::Session], and various others, I've been able to create powerful web applications. Another note, I feel that the module is newbie friendly, as I myself is a newb ;-). Further info can be found on CPAN, and the docs are very easy to read. So far, I have no displeasures with this module, please, reply with your opinions.
<p />
Thanks,
<p />
DeFyance
A great module for creating HTML templates.