Discussion:
[FreeMarker-user] Javascript + jquery + php page
Håvard Wahl Kongsgård
2011-08-27 18:57:10 UTC
Permalink
Hi, without success, I experimented with including simple Javascript
Ajax code interacting with a PHP site in freemaker templates.

example
http://yensdesign.com/2009/01/create-a-shoutbox-using-php-and-ajax-jquery/

With the current version of freemaker is it possible to include this
type of code in freemarker templates?
--
Håvard Wahl Kongsgård
Daniel Dekany
2011-08-27 21:20:21 UTC
Permalink
FreeMarker just generates text (like HTML, JavaScript, whatever) on
the *server* side. So of course you can have AJAX, jQuery etc. on your
FreeMarker-generated web pages. But mind you, JavaScript runs on the
*client*, and hence after FreeMarker was generated the page.

You can't (or shouldn't) use FreeMarker on the same way as you use
PHP. With PHP you do all the program logic including the presentation,
while with FreeMarker you do the presentation only. FreeMarker is for
MVC frameworks, where it's used for the MVC View. Do the non-View
programming in Java, Groovy, Scala, or whatever you prefer, but not in
FreeMarker. (Or if you don't need MVC, you don't want to use
FreeMarker.)
Post by Håvard Wahl Kongsgård
Hi, without success, I experimented with including simple Javascript
Ajax code interacting with a PHP site in freemaker templates.
example
http://yensdesign.com/2009/01/create-a-shoutbox-using-php-and-ajax-jquery/
With the current version of freemaker is it possible to include this
type of code in freemarker templates?
--
Best regards,
Daniel Dekany
Håvard Wahl Kongsgård
2011-08-28 09:05:09 UTC
Permalink
Thanks, but is it possible to integrate SQL with FreeMarker? I use
geoserver(FreeMarker is the template engine). I only need to do some
simple inserts from a form to a postgresql database.

-Håvard
Post by Daniel Dekany
FreeMarker just generates text (like HTML, JavaScript, whatever) on
the *server* side. So of course you can have AJAX, jQuery etc. on your
FreeMarker-generated web pages. But mind you, JavaScript runs on the
*client*, and hence after FreeMarker was generated the page.
You can't (or shouldn't) use FreeMarker on the same way as you use
PHP. With PHP you do all the program logic including the presentation,
while with FreeMarker you do the presentation only. FreeMarker is for
MVC frameworks, where it's used for the MVC View. Do the non-View
programming in Java, Groovy, Scala, or whatever you prefer, but not in
FreeMarker. (Or if you don't need MVC, you don't want to use
FreeMarker.)
Hi, without  success, I experimented with including simple Javascript
Ajax code interacting with a PHP site in freemaker templates.
example
http://yensdesign.com/2009/01/create-a-shoutbox-using-php-and-ajax-jquery/
With the current version of freemaker is it possible to include this
type of code in freemarker templates?
--
Best regards,
 Daniel Dekany
Daniel Dekany
2011-08-28 09:24:32 UTC
Permalink
Post by Håvard Wahl Kongsgård
Thanks, but is it possible to integrate SQL with FreeMarker?
Well, if you put a JDBC Connection or DataSource into the data-model,
I'm certain FreeMarker's reflection support's enough for issuing
queries... But I would not recommend that, as it's awkward and all.
The FreeMarker-ish way is writing a (few) TemplateDirectiveModel
implementations instead, something that you could use like this for
example:

<@sqlExec "INSERT INTO foo(X, Y) VALUES(?, ?)" x y />

<@sqlSelect "SELECT id name FROM foo"; row>
... ${row.id} ... ${row.name} ...
</@sqlSelect>

For that you write a TemplateDirectiveModel and put that into the
data-model with name "sql", or pull it into an #imported/#included
file with <#assign sqlExec = "com.example.SqlExecDirective"?new()>.

Still, data-base modifications should clearly be done outside the
template according the MVC principles, in the Controller.
Post by Håvard Wahl Kongsgård
I use geoserver(FreeMarker is the template engine). I only need to
do some simple inserts from a form to a postgresql database.
-Håvard
Post by Daniel Dekany
FreeMarker just generates text (like HTML, JavaScript, whatever) on
the *server* side. So of course you can have AJAX, jQuery etc. on your
FreeMarker-generated web pages. But mind you, JavaScript runs on the
*client*, and hence after FreeMarker was generated the page.
You can't (or shouldn't) use FreeMarker on the same way as you use
PHP. With PHP you do all the program logic including the presentation,
while with FreeMarker you do the presentation only. FreeMarker is for
MVC frameworks, where it's used for the MVC View. Do the non-View
programming in Java, Groovy, Scala, or whatever you prefer, but not in
FreeMarker. (Or if you don't need MVC, you don't want to use
FreeMarker.)
Hi, without  success, I experimented with including simple Javascript
Ajax code interacting with a PHP site in freemaker templates.
example
http://yensdesign.com/2009/01/create-a-shoutbox-using-php-and-ajax-jquery/
With the current version of freemaker is it possible to include this
type of code in freemarker templates?
--
Best regards,
 Daniel Dekany
--
Best regards,
Daniel Dekany
Daniel Dekany
2011-08-28 09:26:40 UTC
Permalink
Sunday, August 28, 2011, 11:24:32 AM, Daniel Dekany wrote:

[snip]
Post by Daniel Dekany
For that you write a TemplateDirectiveModel and put that into the
data-model with name "sql",
[snip]

I meant, "sqlExec" and like...
--
Best regards,
Daniel Dekany
Loading...