I would like to make use of the
HTML::Template
module but somehow I can't set it up to work properly. Here is a very simple representative code I'm testing on:
use strict;
use warnings;
use CGI;
use HTML::Template;
my $test = new CGI;
my $tmpl = HTML::Template->new(filename => 'TemplateSimple.html');
$tmpl->param(
title => 'Test',
body => '<p>This is a test</p>',
);
my $out = $test->header(
-type => 'text/html',
-charset => 'utf-8'
);
print $out;
print $tmpl->output;
When calling the page I always end up with the browser displaying the server error message:
502 - Web server received an invalid response while acting as a gateway or proxy server.
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title><TMPL_VAR NAME=title></title>
<link rel="SHORTCUT" ICON href="favicon.ico" />
</head>
<body>
<TMPL_VAR NAME=body>
</body>
</html>
I have to use CGI, because I want to process user input on the web page, but I would like to define the basic HTML structure in a template where I can insert code segments as necessary.
I think that it could have something to do with different configs between the local Perl (run from eclipse, which does run fine) and the Perl CGI config. Does anybody know of such a case?
After setting up a Perl CGI configuration in Eclipse, the script runs as expected from the local host. However, the problem when calling the page from an external source persists. So like DaveCross suggested, the bug lies in the web server configuration rather than the Perl script.
When initializing the HTML::Template
object in the Perl script
my $tmpl = HTML::Template->new(filename => 'TemplateSimple.html');
I had to specify the full path instead of just the filename, so
my $tmpl = HTML::Template->new(filename => 'C:/inetpub/wwwroot/Project/TemplateSimple.html');
This solved my problem.
To whom it may interest, the webservice was set up with IIS 7, in the very basic and standard way.