Lightweight CGI Library

The CGI Variable library

This library intends to help people maintaining web sites with included CGI-support, e.g. as connection to a database or something else.

The library helps you to divide between design and content. Thus the person who works on web design does not need to know about programming and the person who does the actual cgi programming does not need to know anything about HTML and web design.

The past has shown that often these people only want or can work on one of the two issues but not on both. However, you'll need to understand that design and content are divided and the person writing the CGI program does not need (or does now want) to munch with HTML.

Supported languages

Currently only Perl is supported. Support for C is urgently required, though.

Installation

Place the file cgivar.pl in /usr/local/lib/site_perl/ or whereever your Perl installation expects additional .pl files.

Usage

To add cgivar support to your programm, simply add the following line at the top of it:

    require 'cgivar.pl';		# HTML-Parser
You will have to open the template file first and pass an arbitrary amount of (name,value) pairs to the display routine. The template is loaded with:

    &cgivar_load ($template);
Where $template refers to the full path to the template. You may call your template foo.html in order to let Editors (preferred: Emacs) recognize it as HTML file. This will make the library evaluate the template and store it in its internal data structures. You may load more than one template at the same time.

If that's done you may now fill a hash with (name,value) pairs such as:

    $cgivar{'name'} = 'Martin Schulze';
    $cgivar{'email'} = 'joey@linux.de';
Then let the library display the file by issuing the following command:

    print &cgivar_eval_head ($template,\%cgivar);
As you can imagine the file is divided in more than just one part. Indeed currently four parts are supported:

HEAD
Head of a template.
FOOT
Foot of a template.
ENTRY
Middle part of a template, may be repeated.
ALTERNATE
Alternate middle part, e.g. if no entries were found.
Dividing up a template gives you a chance to provide variable HTML code if this is required, e.g. when browsing through entries of a database. In that case, you will call cgivar_eval_entry() as often as you need.

The template

The template is - you guessed it - HTML code basically. However, some variables need to be present to be replaced by their actual values. These are denoted by <cgivar name>.

A simple example would be:

    <html>
    <head><title><cgivar title></title></head>
    <body>
    <h1><cgivar title></h1>
    </body>
    </html>
When using different parts of a template you'll divide it up as follows:

    [head]
    <!-- Begin Entry -->
    [entry]
    <!-- Alternate Entry -->
    [alternate]
    <!-- End Entry -->
    [foot]

Download

here

 

News
2009-02-08 Version 0.7 released more2008-04-06 Version 0.6 released more2001-01-02 Web pages for this project more

Download
Version 0.7 (262 kB)
Version 0.6 (24 kB)
Version 0.5 (13 kB)
Version 0.4 (8 kB)

Contributors
Miguel Freitas
Mikko Torni
Neil Spring
Michael Petullo
Laszlo Zavaleta