http://qs1969.pair.com?node_id=245501

Item Description: A great module for creating HTML templates.

Review Synopsis:

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.

Taken from the CPAN docs HTML::Template:

Create a simple HTML page, with two template variables HOME and PATH, name it test.tmpl.
We will fill the variables with data below.

<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>

Now, lets build a program to fill in those previously named variables. The result is displayed below

#!/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;

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:

My Home Directory is /home/some/directory My Path is set to /bin;/usr/bin
Simple, no?

It Gets Better

Not only does it support simple variables, you can also:

  • Escape HTML from your data!
  • Set default values, if data is not supplied by param!
  • Build Loops!
  • Include other templates!
  • Build Conditionals!
  • Error handling has descriptive error output, which speeds up debugging!
  • And much more!

    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 CGI, DBD::mysql, 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.

    Thanks,

    DeFyance