Monday, May 14, 2012

Designing Your Own Web Template Toolkit in 2 Minutes


The purpose of this article is to demonstrate web templates and to quickly write one to experience how template toolkits work at the most basic level. The goal is to help beginners understand the basic principles.

What is a Web Template?

The most common purpose of standard template toolkits is to separate presentation from logic. Presentation is usually referred to by markup languages like HTML, XHTML. Logic is the part handled by programming languages like PHP, Perl, Python, Ruby, etc.

Standard Web Template Toolkits



There are many open source web template toolkits available. For example,

Perl: Template.pm module
PHP: Smarty
Python: Cheetah
Ruby: Web::Template module
The feature sets of these standard template toolkits can be fairly large. There are many built-in functions that can completely separate presentation from logic.

Let's Write Our Own Web Template Toolkit

We will create two files:

index.pl: will contain Perl codes
template.inc: will contain HTML codes
Let's start easy and write the template.inc file:


--------------------
# file: template.inc

<html>

<head></head>

<body>

< h1 >Our Company< /h1 >

{{content}}

<small>Copyright Foo Bar</small>

</body>

</html>

--------------------

Note that we have defined a template variable above enclosed in {{}} as {{content}}. We will parse this template variable in our Perl code in index.pl.



Article Source: http://EzineArticles.com/199688 Read Full Story

You may also like:
Think You Have Got it Made with a Web Template
About Web Templates

No comments:

Post a Comment