Designing Your Own Web Template Toolkit in 2 Minutes

The purpose of this article is to demonstrate web< h1 >Our Company< /h1 >
templates and to quickly write one to experience{{content}}
how template toolkits work at the most basic level.<small>Copyright Foo Bar</small>
The goal is to help beginners understand the basic</body>
principles.What is a Web Template?</html>
The most common purpose of standard template--------------------
toolkits is to separate presentation from logic.Note that we have defined a template variable
Presentation is usually referred to by markupabove enclosed in {{}} as {{content}}. We will parse
languages like HTML, XHTML. Logic is the part handledthis template variable in our Perl code in index.pl.
by programming languages like PHP, Perl, Python,--------------------
Ruby, etc.Standard Web Template Toolkits#!/usr/bin/perl
There are many open source web template toolkits# file: index.pl
available. For example,use CGI qw/:standard/;
print header;my $content = "Welcome to our
Perl: Template.pm modulewebsite. This is the main content area...blah blah, yada
PHP: Smartyyada yada";open(FH, 'template.inc') || die "Can't open
Python: Cheetahfile; $!n";
Ruby: Web::Template modulewhile(my $line=) {$line =~ s/{{content}}/$content
The feature sets of these standard template;print $line;
toolkits can be fairly large. There are many built-in}
functions that can completely separate presentationclose FH;
from logic.Let's Write Our Own Web Template--------------------
ToolkitLet's analyze the code further:
We will create two files:#!/usr/bin/perl
use CGI qw/:standard/;
index.pl: will contain Perl codesprint header;
template.inc: will contain HTML codesThe above block initializes the perl script, uses the
Let's start easy and write the template.inc file:CGI module and sends some basic headers to the
--------------------browser.
# file: template.incmy $content = "Welcome to our website. This is
<html>the main content area...blah blah, yada yada yada";
<head></head>This declares what the content of the site will be.
<body>open(FH, 'template.