Dear Monks,

Using Template Toolkit, I can only get a blank page to display after processing my template. Here is my simple template:
<!DOCTYPE html> <html> <head><title>Test</title></head> <body> <div>From template:</div> <div>[% message %]</div> </body> </html>
Here is the CGI program that tries to send that template to the browser:
#!/usr/bin/env perl use strict; use warnings; use Template; my $tname = 'templates/form.html'; my $vars = { message => "Hello World\n" }; my $template = Template->new({ INCLUDE_PATH => '/Users/7stud/perl_programs/cgi_projects/1proj') }); $template->process($file, $vars) or die "*MY* template process failed: ", $template->error(), "\n";
That program is essentially copied from the docs.

Here is my directory structure:

1proj/ ---cgi-bin/ ------create_form.pl -------simple_cgi.pl ---serverHTTP.py ---templates/ -------footer.html -------form.html -------header.html ------xform.html 2 directories, 8 files
Here is create_form.pl:
#!/usr/bin/env perl use strict; use warnings; use Template; my $tname = 'templates/form.html'; my $vars = { message => "Hello World\n" }; my $template = Template->new({ INCLUDE_PATH => '/Users/7stud/perl_programs/cgi_projects/1proj') }); $template->process($file, $vars) or die "*MY* template process failed: ", $template->error(), "\n";
The url I'm using in my browser is:
http://localhost:8000/cgi-bin/create_form.pl
According the the Template Toolkit docs:
The process() method is called to process a template. The first parameter indicates the input template as one of: a filename relative to INCLUDE_PATH, if defined;.... docs
I am able to send a request to the program simple_cgi.pl, which does not use a template, and it works as expected. The url I use for that request is similar:
http://localhost:8000/cgi-bin/simple_cgi.pl
Here is simple_cgi.pl:
#!/usr/bin/env perl use strict; use warnings; use CGI; use CGI::Carp qw{ fatalsToBrowser }; my $cgi = CGI->new; print $cgi->header, $cgi->start_html, $cgi->div('hello'), $cgi->end_html;
What am I doing wrong?

In reply to Template Toolkit: template paths, INCLUDE_PATH, error by 7stud

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.