Red Antigua Logo
Yet another piece of web.
Search this site (by Google)
Tools    (top)
Check a site for broken links
(W3C)

Perl modules    (top)
Tree::Numbered::Tools
(CPAN)
Perl tutorials    (top)
Perl modules
HTML::Template
CGI::Application
Cookies with CGI::Application
Upload files with CGI::Application
Download files with CGI::Application
Redirect with CGI::Application
CPAN shell
Install DBD::mysql from the CPAN shell
Perl trim function
Validate an IP with Perl
Run suid Perl scripts under Apache
Perl taint mode
Perl date functions with Date::Calc

In Spanish
Curso de Perl

C tutorials    (top)
C - Introduction
C - Absolute beginner's Emacs
C - Examples for beginners
C - Makefile examples
C - Autotools examples
Server configurations    (top)
DNS
Apache
Apache Authentication and Access Control
mod_perl on FreeBSD
MySQL
MySQL add account
phpMyAdmin
Squid
DHCP

UNIX on Windows    (top)
MSYS2 - UNIX environment for MS Windows 32/64 bits
Apache setup on Windows
MySQL setup on Windows
PHP setup on Windows
Perl setup on Windows
Emacs setup on Windows
PuTTY
WinSCP
GIMP on Windows
MinGW - gcc on Windows
MSYS - UNIX-styled shell on Windows
msysDTK - autotools on Windows
GDB for MinGW on Windows

Misc. FreeBSD/UNIX    (top)
'portupgrade' on FreeBSD
'ipf' on FreeBSD
'pf' on FreeBSD
'su' on FreeBSD
Mount an ISO image under FreeBSD
Load the correct sound driver under FreeBSD without knowing what sound card you are using
Simultaneous sound channels on FreeBSD
FreeBSD network stuff
DOS-to-UNIX file conversion
favicon.ico on UNIX
Emacs tips
Command Line Calculator
Save multimedia streams with 'mplayer'
xargs - solution to 'Argument list too long'
Process multiple images from the command line using 'ImageMagick'
Turn the system bell off under X Windows
Process each line in an input file from the command line (or in a shell script)
How to keep a program running in the background using 'nohup'
How to remove symbolic links in the current directory using 'find' and 'rm'
How to remove Emacs backup files in the current directory and all subdirectories using 'find' and 'rm'
How to execute .profile without logging in
Configure X to handle non-English characters
How to move /var to /usr/var
5 Best Homework Help Websites 2023

Redirect a web page    (top)
Redirect to another web page
Apache redirect
C redirect
Perl redirect
PHP redirect
HTML redirect
JavaScript redirect

Javascript    (top)
Trim function
Login form
Register form
Popup window

HTML::Template Tutorial
HTML::Template - step by step
IndexPreviousNext
2. "Hello, World!", using HTML::Template
Create a file called helloworld.tmpl.html:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title><TMPL_VAR NAME=THAT_FAMOUS_STRING></title>
</head>
<body>
<b><TMPL_VAR NAME=THAT_FAMOUS_STRING></b>
</body>
</html>
and a file called helloworld.tmpl.pl:
#!/usr/bin/perl
##
##  HTML template Hello World
##
use strict;
use HTML::Template;

my $that_famous_string = 'Hello, world!';

# open the html template
my $template = HTML::Template->new(filename => 'helloworld.tmpl.html');
# fill in some parameters
$template->param(THAT_FAMOUS_STRING => $that_famous_string);
# send the obligatory Content-Type
print "Content-type: text/html\n\n";

# print the template
print $template->output;
Run the script from the command line:
# perl -w helloworld.tmpl.pl
or in your browser (don't forget to configure DNS and Apache first):
# chmod 755 helloworld.tmpl.pl
# cp helloworld.tmpl.pl /usr/local/apache/cgi-bin/.
# opera http://localhost/cgi-bin/helloworld.tmpl.pl
which should look like this.

Two files instead of one. And the same output as the previous example. So what's the deal?
Well, now you can pass "helloworld.tmpl.html" to your web designer to modify it in her/his favorite HTML editor.
(Just tell her/him not to touch the HTML tags starting with "<TMPL_".)
To redesign yor application's look, you don't have to modify your code at all.
A redesigned template using the same Perl code as above can look like this.

IndexPreviousNext
Last modified: Mon Aug 6 23:28:15 CEST 2007