Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-04

fptemplate example wrong?

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

Hello,

I was following the simpletemplate example for fptemplate, where, in webmodule.pas, it says:

  //ModuleTemplate is a web module global property
  //To use the Template propery of the current web action (which is
visible in
  //the object inspector for every Action), use
  //(Sender as TFPWebAction).Template.FileName := 'mytemplate1.html';
and so on.
  ModuleTemplate.FileName := 'mytemplate1.html';//best to use full path here
  ModuleTemplate.AllowTagParams := true;
  ModuleTemplate.OnReplaceTag := @func1callReplaceTag;

but it didn't work in my program.
It turns out that the correct OnReplaceTag event to assign is the one of the module itself and not of ModuleTemplate, i.e.:

instead of

ModuleTemplate.OnReplaceTag := ...

it should be

OnReplaceTag :=

I'm using it in a standalone server app, and I used the OnGetParam event (AllowTagParams is false, I previously tried OnReplaceTag just like the example), while the example is for a cgi/fastcgi app, but I don't think that makes a difference.

Bye

Luca
leledumbo
to Luca Olivetti
but it didn't work in my program.

The example works just fine with embedded server, only need to adjust path to the template. So you might want to send a minimal example that shows it doesn't work as you describe.

It turns out that the correct OnReplaceTag event to assign is the one of the module itself and not of ModuleTemplate, i.e.:

There's on OnReplaceTag in TFPWebModule...

It's very likely that you misunderstood fpWeb application flow.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/fptemplate-example-wrong-tp5721613p5721614.html Sent from the Free Pascal - General mailing list .
Luca Olivetti
to leledumbo

El 18/04/15 a les 07:54, leledumbo ha escrit:

Show quoted text 12 lines
> but it didn't work in my program. The example works just fine with embedded server, only need to adjust path to the template. So you might want to send a minimal example that shows it doesn't work as you describe. > It turns out that the correct OnReplaceTag event to assign is the one of > the module itself and not of ModuleTemplate, i.e.: There's on OnReplaceTag in TFPWebModule... It's very likely that you misunderstood fpWeb application flow.

You are right, the example works, and I'm surprised: I couldn't manage to make it work in my application (and now I don't know why). Since I'm not using actions, I thought that might be the problem and modified my module to use actions just like the example. That didn't work either (again, now I don't understand why), so I tried with AllowTagParams:=false and ModuleTemplate.OnGetParam instead. Since that didn't work either, I traced it and it turns out that what I said in my original email applies only to OnGetParam: ModuleTemplate.OnGetParam is never called, instead you have to use OnGetParam of the module itself.
Probably I made some stupid error in my firsts attempts, and the inconsistency between OnGetParam/OnReplaceTag didn't help.

Bye

Luca
ABorka
to Luca Olivetti

The OnGetParam and OnReplaceTag are two totally different ways to handle templates. The former is the original version found in FPC packages, the latter is the newer, more Delphi-like - although enhanced - way to do templates. The two are mutually exclusive and controlled by the AllowTagParams flag (false -> old way, true -> new way).

The fptemplate.txt file under the FPC sources,
.../packages/fcl-base/texts/fptemplate.txt might help a little.

All the examples should work, BTW, with the new way, under .../packages/fcl-web/examples/fptemplate/...

AB

Luca Olivetti
to ABorka

El 18/04/15 a les 14:16, ABorka ha escrit:

Show quoted text 5 lines
The OnGetParam and OnReplaceTag are two totally different ways to handle templates. The former is the original version found in FPC packages, the latter is the newer, more Delphi-like - although enhanced - way to do templates. The two are mutually exclusive and controlled by the AllowTagParams flag (false -> old way, true -> new way).

I saw that, it's clearly indicated in the source

The fptemplate.txt file under the FPC sources, .../packages/fcl-base/texts/fptemplate.txt might help a little.

Thank you, I didn't see it. It explains how the new way works, but it doesn't explain why the old one uses the web module's OnReplaceTag event instead of the ModuleTemplate's one (or vice versa).

Bye

Luca