7stud has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
<!DOCTYPE html> <html> <head><title>Test</title></head> <body> <div>From template:</div> <div>[% message %]</div> </body> </html>
#!/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";
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
#!/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";
http://localhost:8000/cgi-bin/create_form.pl
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
http://localhost:8000/cgi-bin/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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Template Toolkit: template paths, INCLUDE_PATH, error
by 7stud (Deacon) on Jan 06, 2015 at 11:25 UTC | |
Re: Template Toolkit: template paths, INCLUDE_PATH, error
by 7stud (Deacon) on Jan 06, 2015 at 11:37 UTC |