Freepascal templating engines with logical structures

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Freepascal templating engines with logical structures

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal templating engines with logical structures

ABorka
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

On 9/16/2014 21:51, luciano de souza wrote:

> 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,
>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal templating engines with logical structures

leledumbo
Administrator
> 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 | Threaded
Open this post in threaded view
|

Re: Freepascal templating engines with logical structures

gabor-10
In reply to this post by Luciano de Souza
Hello Luciano,

W dniu 2014-09-17 06:51, luciano de souza pisze:
> Are there templating engines in Pascal with support for logical structures?

I found this some time ago:
http://dvdchief.com/delphi/

I made some work on porting it to FreePascal. But I have not tested it
too much. Requires FreePascal 2.7.1

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

templateengine.zip (163K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Freepascal templating engines with logical structures

Luciano de Souza
In reply to this post by Luciano de Souza
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 <[hidden email]>:

> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal