Adam Jimerson wrote:
No I am letting CGI.pm generate the HTML for me, I figured that it would
be the easiest way to do it.
Most people find that templates are simpler for most purposes (since they can then just write HTML and say "Insert data here" rather then describing every element in Perl).

- From what I see in the tutorial,
http://template-toolkit.org/docs/tutorial/Web.html#section_Dynamic_Content_Generation_Via_CGI_Script,
the Templete Toolkit only outputs information from the script, but I
need it to handle input as well
You use Perl to handle the input. TT is just for making it easy to write the output.

I've just remembered this simpler example:
http://github.com/dorward/simple-ajax-demo/tree/master

The script itself is at http://github.com/dorward/simple-ajax-demo/tree/master/webroot/demo.pl

Line 32 gets user input, in exactly the same way that CGI.pm would do (I'm using CGI::Fast for this, which is similar).

Line 33 uses that input to change what request gets sent to the database on ...

Line 42 (which) gets a list of messages from the database (much like a guestbook would).

Line 49 wraps it up in a hash.

Ignore lines 51 to 56, these output JSON instead of HTML.

Line 59 gives that hash to a template.

http://github.com/dorward/simple-ajax-demo/tree/master/templates/html.tt is that template.

Lines 15 to 21 of that template loop over the data and output HTML.

The rest of the template is plain, simple HTML which is easy to edit (and line 6 pulls a stylesheet in).

--
David Dorward
http://dorward.me.uk/

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/


Reply via email to