Sign in Join

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

Mailing lists / fpc-pascal / 2014-09

Freepascal templating engines with logical structures

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

luciano de souza

Hello all,

I Know two templating engines for Freepascal: FPTemplate e JTemplate. Both can be successfully used for html construction.

But they presents the same aspect: only searches and replaces tags to values.

Of course, it's crucial. But to show html grids, obtained from database queries, it would be better if the templating engine had support for logical structures. Something like:

<table>
<%
for row in rows do
begin
write('<tr>');
for cell in cells do
writeln('<td>%s</td>', [cell]);
write('</tr>');
end;
%>
</table>

It's only an example. The engine can use a syntax different from Pascal.

But what I really like is not to use Javascript. Yes, in the Pascal side, I could write a JSON and certainly, there would be several Javascript libraries to show a grid from a JSON. However, I would like a pure Pascal solution.

Are there templating engines in Pascal with support for logical structures?

Regards,

Luciano de Souza

Reply by email

ABorka
to luciano de souza

You do not need to use javascript. There are examples for fpTemplate on how to do this. See .../packages/fcl-base/texts/fptemplate.txt for details. Examples are in .../packages/fcl-web/examples/fptemplate/...

All your logic (loop) can be in your fpc source code for grids.

What you seem to want is something php-like, to interpret commands from the html template. But that way the program logic and display template would not be separate.

AB

luciano de souza wrote 34 lines
Hello all, I Know two templating engines for Freepascal: FPTemplate e JTemplate. Both can be successfully used for html construction. But they presents the same aspect: only searches and replaces tags to values. Of course, it's crucial. But to show html grids, obtained from database queries, it would be better if the templating engine had support for logical structures. Something like: <table> <% for row in rows do begin write('<tr>'); for cell in cells do writeln('<td>%s</td>', [cell]); write('</tr>'); end; %> </table> It's only an example. The engine can use a syntax different from Pascal. But what I really like is not to use Javascript. Yes, in the Pascal side, I could write a JSON and certainly, there would be several Javascript libraries to show a grid from a JSON. However, I would like a pure Pascal solution. Are there templating engines in Pascal with support for logical structures? Regards,

Reply by email

leledumbo
to ABorka
What you seem to want is something php-like, to interpret commands from

the html template. But that way the program logic and display template would not be separate.

Right, even a simple for/if statement means there's logic in the template, which is not desirable. Template should serve as a template, not more. It should provide parameters for the processing code for flexible display so flexible display can still work. Here's an example for table and list formatting of the same values:

https://github.com/leledumbo/QTemplate/blob/master/examples/simple/test.tpl https://github.com/leledumbo/QTemplate/blob/master/examples/simple/test.lpr

Reply by email

luciano de souza
to luciano de souza: I Know two templating engines for Freepascal: FPTemplate e JTemplate. Both can be…

Thank you. The options you had me done are very intersting.

I want to show HTML grids and I intend to use a templating engine for this purpose. But, in stead of embed logics in the template, I think I need to organize better my code.

Perhaps, I need to build a class THMLTable where I could set a dataset to be shown and paginated. And by means of a text property, I can fill the template with one of the presented engines.

2014-09-17 1:51 GMT-03:00, luciano de souza :

Show quoted text 38 lines
Hello all, I Know two templating engines for Freepascal: FPTemplate e JTemplate. Both can be successfully used for html construction. But they presents the same aspect: only searches and replaces tags to values. Of course, it's crucial. But to show html grids, obtained from database queries, it would be better if the templating engine had support for logical structures. Something like: <table> <% for row in rows do begin write('<tr>'); for cell in cells do writeln('<td>%s</td>', [cell]); write('</tr>'); end; %> </table> It's only an example. The engine can use a syntax different from Pascal. But what I really like is not to use Javascript. Yes, in the Pascal side, I could write a JSON and certainly, there would be several Javascript libraries to show a grid from a JSON. However, I would like a pure Pascal solution. Are there templating engines in Pascal with support for logical structures? Regards, -- Luciano de Souza
Luciano de Souza

Reply by email