It's really an ugly hack, but you can do something like:
# Process this once to catch any errors, but discard all the
# output. We'll run it again to actually get the output.
open SAVEOUT, ">&STDOUT"; # stash the original output stream
open STDOUT, "> /dev/null"; # discard all output
unless($template->process($file, $vars, $r)) {
# Do your error processing stuff.
exit;
}
open STDOUT, ">&SAVEOUT"; # redirect back to original stream
close SAVEOUT;
# Do it for real.
$template->process($file, $vars, $r);
Please note that this does processes your template twice every time the script is run, which is a performance hit. A better option is to do some kind of test on your App before it's run to make sure all the templates are valid.
http://lxr.mozilla.org/mozilla/source/webtools/bugzilla/t/004template.t
http://lxr.mozilla.org/mozilla/source/webtools/bugzilla/t/Support/Templates.pm
The URL's above are to the source files for some tests I did to make sure the templates we ship with Bugzilla are valid. (As you can see, the STDOUT redirection I mentioned above is taken from 005template.t) These tests run and report to the tinderbox continuous build server at http://tinderbox.mozilla.org/Bugzilla/
-----Original Message-----
From: dss [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 18, 2001 5:38 PM
To: [EMAIL PROTECTED]
Subject: [Templates] $template->process - handling errors/headers
Hello,
I'd like to have apache 404 errors and
template-toolkit errors both go to the same error
page. I've set httpd.conf, but I'm having trouble with
TT. I've modified the code from the TPC Slide Show
(NOT_FOUND instead of SERVER_ERROR), but in either
case, an extra header shows up. Is there anyway to do
this without the extra header appearing?
Thanks.
--
package MyPackage;
use strict;
use Template;
use Apache::Constants qw( :common );
sub handler {
my $r = shift;
$r->content_type('text/html');
$r->send_http_header;
my $template = Template->new({
INCLUDE_PATH => '/usr/local/templates',
});
my $file = 'missingtemplate.html';
my $vars = {
message => 'The Cat Sat on the Mat',
};
$template->process($file, $vars, $r) || do {
$r->log_reason($template->error,
$r->filename);
return NOT_FOUND;
};
return OK;
}
1;
__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates
