help files
Z505 | PasWiki | FUQ | Search | Main Docs | API Guide



Notes

WebApplication is a powerful template system that reduces the otherwise fragmented development that occurs when using the more simple webfileout and webtemplateout functions scattered throughout the code.

The WebApplication framework allows one to prepare the template with lists of data before making the decision to emit it. This is different than the simpler webtemplateout and webfileout functions which required multiple templates to be used if one wanted to output a list of table cells for example, in a loop.

History/About

See Jorge's WebApp Introduction

Code

It is in development, see SVN here.

Examples

On SVN there are some examples in the Trunk folder.

Look for exampleapp.pp and exampleapp_list.pp in the SVN trunk directory.

A simple example of loading some values into a List or Array an then emitting them would be as seen below.

First our exampleapp_list program uses a template such as:

<html>
<head>
<title>Hello world !</title>
</head>
<body>
 Hello customer,<br>
 <listofsomething>
   This is a <name> and its value is <value><br>
 </listofsomething>
</body>
</html>
This template can output the following data:
X-Powered-By: PWU/1.6.0.2
Content-Type: text/html; charset=iso-8859-1

<html>
<head>
<title>Hello world !</title>
</head>
<body>
  Hello customer,<br>
  This is a Car and its value is 5000<br>
  This is a Car2 and its value is 5050<br>
  This is a Car3 and its value is 5500<br>
  This is a Car4 and its value is 5005<br>
  This is a Car5 and its value is 10500<br>
</body>
</html>

As you can see above, there are several items displayed at once, even though only a single simple template needed to be created.

A real application that could use this would be for example a store with several inventory items, or a forum with several posts and titles, or a blog, etc.

The program code that runs this application:

Uses
    Classes,
    Sysutils,
    PWUMain,
    HTMLBase,
    WebTemplate;

// Suppose you must show a list of a record, using traditional PWU
// templates wont help much, so you do :

Const
    ListOfSomething : Array<1..5> Of Record
        ItsName  : String;
        ItsValue : LongWord;
    End =
    ((ItsName : 'Car'; ItsValue : 5000),
     (ItsName : 'Car2'; ItsValue : 5050),
     (ItsName : 'Car3'; ItsValue : 5500),
     (ItsName : 'Car4'; ItsValue : 5005),
     (ItsName : 'Car5'; ItsValue : 10500));

// Global variable that the child tags will use to know where they are
Var Current : Byte;

Type
    // Tag Handlers used in our project : Show current name
    TCurrentName = Class(THTMLTag)
    Public
        Procedure Emit; Override;
    End;

    // Tag Handlers used in our project : Show current value
    TCurrentValue = Class(THTMLTag)
    Public
        Procedure Emit; Override;
    End;

    // Tag Handlers used in our project : Iterate thru all childs incrementing
    // the current position and asking childs to emit again
    TListOfSomething = Class(THTMLTag)
    Public
        Procedure Emit; Override;
    End;

    TMyTemplate = Class(TWebTemplate)
    Public
        Procedure Run;
    End;

Procedure TCurrentName.Emit;
Begin
    WebWrite(ListOfSomething.ItsName);
End;

Procedure TCurrentValue.Emit;
Begin
    WebWrite(IntToStr(ListOfSomething.ItsValue));
End;

Procedure TListOfSomething.Emit;
Begin
    Gotop;
    For Current := 1 To 5 Do
        EmitChilds;        
End;

Procedure TMyTemplate.Run;
Begin
    NameSpace.AppendBuilder('name', TCurrentName, False);
    NameSpace.AppendBuilder('value', TCurrentValue, False);
    NameSpace.AppendBuilder('listofsomething', TListOfSomething, True);
    Load;
    Emit;
End;

Var
    fTemplate : TMyTemplate;

Begin
    fTemplate := TMyTemplate.Create('listexample.tpl');
    fTemplate.Run;
    fTemplate.Free;
End.
The WebApplication framework allows one to build powerful web programs using templates, without even using #INCLUDE directives, and without using perl style $variables, and without calling webtemplateout and webfileout manually in fragments.





lufdoc, Powtils, fpc, freepascal, delphi, kylix, c/c++, mysql, cgi web framework docs, Z505