Webpage 1.0 - Web page macro facility

Difference between version 2 and 3 - Previous - Next
**Webpage 1.0 - A pure TCL extension package for generating HTML pages**

This extension package was created out of boredom with the endless labour of writing pure HTML pages which inevitably require the repeated composition of lines of HTML statements that are basically the same except for parameter values. What the package does is implement a system of ''templates'' that are written using a combination of ''HTML'' ''text'', ''parameters'', and ''markups'' that implement some basic constructs including ''foreach'', ''repeat'' and ''duplicate'' loops, ''if/else'' conditionals and a few ''utility markups'' for documentation and debugging.

The package allows for the creation of ''template'' collections which are marked up ''HTML'' files that are ''parametrized'' such that when expanded, the various parameters are expanded to generate the final HTML text. A simple example of a ''template'' might be:


======
# --- basic-input.html --- A parametrized input

!defaults FORM_ID=myform; VALUE=; ID=myinput; TYPE=text

!comment Including basic-input.html

<input type="TYPE" value="VALUE" id="ID" name="ID" form="FORM_ID"/>

!comment End of basic-input.html
======

This ''template'' might then be used in a web page fragment as follows;

======
# --- inputs.html --- A list of hidden inputs

!defaults TYPE=hidden

!foreach name+email+password
    !include basic-input ID="P1"
!end
======

The result would be an ''HTML'' block expanded as:

======
<!-- Including basic-input.html -->
<input type="hidden" id="name" form="myform" value=""/>
<!-- End of basic-input.html -->
<!-- Including basic-input.html -->
<input type="hidden" id="email" form="myform" value=""/>
<!-- End of basic-input.html<!-- Including basic-input.html -->
<input type="hidden" id="password" form="myform" value=""/>
<!-- End of basic-input.html
======

Some of the features of this extension demonstrated here are:

   * Use of # to indicate comment lines in template files

   * The ''!comment'' markup generates HTML comment text in the output

   * The ''!defaults'' line defined default values for the parameters in the HTML text

   * The ''!include'' line shows how to override default values of a parameters in the template

   * The ''!foreach'' line demonstrated how to expand a repetitive list of HTML lines

This is a rather basic demonstration of how the extension works. On linux style machines, you can make use of the ''man'' page included in the distribution to further understand the full list of available ''markups''. The parameter scheme implemented in this extension works in a hierarchy, so where a series of ''templates'' is included in a nested fashion, higher level ''parameter'' definitions continue to apply down the nesting until they are changed. So, in a complex ''form'', for instance, you can carry common ''parameter'' values for ''form'' elements downwards through the nesting with a single higher level definition.

The extension is written completely in TCL, so it will run on Windows systems as well, however, you will have to use
either the included PDF or HTML versions of the man page. Windows users can extract the distribution using some suitable archive manager that handles .deb or .rpm packages, or from the .zip package, and setting up the environment variable TCLLIBPATH as needed, or, perhaps simply sourcing the package source.

One useful aspect of this package is that the expansion of the ''template'' lines happens inside the TCL interp, so, should the ''markup'' system prove inadequate to the needs of the application, any TCL command sequence can be used as well. Things like:

======
!defaults NOW=[clock format [clock seconds]]
======

can make it easy to access system services during template expansion.

The package is available from https://sourceforge.net/projects/tclfltk/files/Linux/webpage/

An HTML file with the documentation can be found at https://sourceforge.net/projects/tclfltk/files/Linux/webpage/webpage.n.html

<<categories>> CGI, | Web D| Tevelopmenplate