PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/components/fpweb/demo/fptemplate/simpletemplate/cgi/webmodule.pas

http://github.com/graemeg/lazarus
Pascal | 61 lines | 38 code | 16 blank | 7 comment | 2 complexity | 0e074e8dd728d3ca43161e50319f4bbd MD5 | raw file
 1unit webmodule; 
 2
 3{$mode objfpc}{$H+}
 4
 5interface
 6
 7uses
 8  Classes, SysUtils, FileUtil, LResources, HTTPDefs, websession, fpHTTP, fpWeb; 
 9
10type
11
12  { TFPWebModule1 }
13
14  TFPWebModule1 = class(TFPWebModule)
15    procedure func1callRequest(Sender: TObject; ARequest: TRequest;
16      AResponse: TResponse; var Handled: Boolean);
17  private
18    { private declarations }
19    procedure func1callReplaceTag(Sender: TObject; const TagString:String; 
20      TagParams: TStringList; Out ReplaceText: String);
21  public
22    { public declarations }
23  end; 
24
25var
26  FPWebModule1: TFPWebModule1; 
27
28implementation
29
30{ TFPWebModule1 }
31
32procedure TFPWebModule1.func1callRequest(Sender: TObject; ARequest: TRequest;
33  AResponse: TResponse; var Handled: Boolean);
34begin
35  Template.FileName := 'mytemplate1.html';
36  Template.AllowTagParams := true;
37  Template.OnReplaceTag := @func1callReplaceTag;
38
39  AResponse.Content := Template.GetContent;
40
41  Handled := true;
42end;
43
44procedure TFPWebModule1.func1callReplaceTag(Sender: TObject; const TagString:
45  String; TagParams: TStringList; Out ReplaceText: String);
46begin
47  if AnsiCompareText(TagString, 'TagName1') = 0 then
48  begin
49    ReplaceText := 'Here I am from the web module!';
50  end else begin
51
52//Not found value for tag -> TagString
53    ReplaceText := 'Template tag {' + TagString + '} is not implemented yet.';
54  end;
55end;
56
57initialization
58  {$I webmodule.lrs}
59
60  RegisterHTTPModule('TFPWebModule1', TFPWebModule1); 
61end.