NAME
HTML::Tmpl - Perl extension handling simple HTML Templates in CGI Scripts
SYNOPSIS
#!/usr/bin/perl -wT
#in CGI app.:
use HTML::Tmpl;
my $tmpl = new HTML::Tmpl(-filename=>"some-template.tmpl");
$tmpl->param(
title => "New Document",
time => scalar( localtime() ),
name => "Sherzod B. Ruzmetov"
);
print "Content-type: text/html\n\n";
print $tmpl->output();
in some-template.tmpl file:
<HTML>
<HEAD>
<TITLE> <%var title%> </TITLE>
</HEAD>
<BODY>
Today's date is <%var time %>
Copyright (c) 2002 <%var name%>
</BODY></HTML>
DESCRIPTION
This documenation refers to Version 1.x of the library
HTML::Tmpl is the lighter version of L<HTML::Template> module by Sam Trager (sam@trager.com)
but with a lot less options. It uses JSP like styled tag sets (<% %>)
As of version 1.1 HTML::Tmpl does only variable replacement. IF you want loop and if/else
features to be available for your HTML templates, please go with L<HTML::Template>.
Of course all the features HTML::Template offers are in my TODO list, and hopefully
will appeare in the subsecquent versions of the library.
METHODS
new()
-
constructor
new()
takes a hash argument which denotes the name of the file to ber parsed as an HTML template. It returns HTML::Tmpl object if it succeeds, undef otherwise.my $tmpl = new HTML::Tmpl(-filename=>"some-template.tmpl");
param()
-
assigns parameters to special tags. It expects arguments in key/value pairs, so it's abolutely legal to give it already existing hash. As an alternative you can pass it a reference to a hash variable. It dereferences it for you. This feature is quite usefull when you want to pass it the result of $dbh-selectrow_hashref(qq|SELECT * FROM table_name WHERE id=?|, undef, $id)> to select a row from an SQL database. Example.,
# profile of the user with id 7 as saved in the 'profiles' table $tmpl->param($dbh->selectrow_hashref(qq|SELECT * FROM profiles WHERE id=?|, undef, 7);
output()
-
when take care of all of your parameter processing (by calling the above
param()
method), at sometime you decide to printout your final template. That's when you use theoutput()
method. Example.,print $tmpl->output();
But don't forget to take care of your own HTTP headers:
print "Content-type: text/html\n\n"; print $tmpl->output();
As an alternative to
output()
you can as well call theprint()
method, which prints it for you to STDOUT. print()
-
similar to
output()
, but instead of returning the processed template, it prints it for you. So you can just say:$tmpl->print; # instead of saying: # print $tmpl->output();
AUTHOR
Sherzod B. Ruzmetov <sherzodr@cpan.org>