Template Toolkit Problem

K

Kevin

I'm getting a Server error - malformed header from script. Bad
header=<html>: template.pl when running a very simple example of
the template toolkit. When I run the script, and redirect output to a
file (.html) it opens nicely in a browser.

Strange it shows < and >

Output from the script is:

<html>
<head><title>Template Toolkit @TPC4</title></head>

<body bgcolor="#ffffff">



<h1>Hello World!</h1>

<p>The Cat Sat on the Mat</p>

</body>
</html>


Here's what I've got:

template.pl
-----------
#!/usr/bin/perl -w

use strict;
use Template;

my $template = Template->new({
INCLUDE_PATH => './templates',
});

my $file = 'welcome.html';
my $vars = {
message => 'The Cat Sat on the Mat',
};

$template->process($file, $vars)
|| die $template->error(), "\n";


templates/header
----------------
<html>
<head><title>[% title %]</title></head>

<body bgcolor="#ffffff">


templates/footer
----------------
</body>
</html>


Any help would be appreciated.

Kevin
 
B

Bob Walton

Kevin said:
I'm getting a Server error - malformed header from script. Bad
header=&lt;html&gt;: template.pl when running a very simple example of
the template toolkit. When I run the script, and redirect output to a
file (.html) it opens nicely in a browser.

Strange it shows &lt; and &gt;

Output from the script is:

<html>
<head><title>Template Toolkit @TPC4</title></head>

<body bgcolor="#ffffff">



<h1>Hello World!</h1>

<p>The Cat Sat on the Mat</p>

</body>
</html>


Here's what I've got:

template.pl
-----------
#!/usr/bin/perl -w

use strict;
use Template;

my $template = Template->new({
INCLUDE_PATH => './templates',
});

my $file = 'welcome.html';
my $vars = {
message => 'The Cat Sat on the Mat',
};

$template->process($file, $vars)
|| die $template->error(), "\n";


templates/header
----------------
<html>
<head><title>[% title %]</title></head>

<body bgcolor="#ffffff">


templates/footer
----------------
</body>
</html> ....


Kevin

This is a FAQ:

perldoc -q 500

You're not generating a HTTP header, which is what your server is trying
to tell you with the error message it gives. And you don't:

use CGI;

which just makes life harder for you.

CGI questions like this (you would have had the same problem if your
script was written in any other language, so it's not a Perl problem)
should be referred to a CGI newsgroup.
 
B

Bill

Gregory said:
Kevin wrote:




Are you sending a Content-Type ??

gtoomey

Exactly, he needs to change ./Template/header to read something like
=== cut ==========
Content-Type: text/html; charset=ISO-8859-1

<html>
<head><title>[% title %]</title></head>

<body bgcolor="#ffffff">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top