Whoops, I hacked up my example a little to make it easier it to read, and I accidentally removed the line: $file =~ s{^/}{}; But, it was in the original. Really. :-)
-Tim ----- Original Message ----- From: "Lyle Brooks" <[EMAIL PROTECTED]> To: "Tim Noll" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, February 05, 2002 4:42 PM Subject: Re: image corruption > When I try this example, I find that this line > > > my $file = $r->path_info; > > will set $file to "/index.html" when I request the URL /tt/index.html > > which leads to an error message that says, > > reason: file error - /index.html: absolute paths are not allowed (set ABSOLUTE option) > > You may want to clip off the leading slash or set the Template Toolkit > option ABSOLUTE, depending on which suits your needs. > > Quoting Tim Noll ([EMAIL PROTECTED]): > > I'm attempting to use mod_perl and Template Toolkit to serve up > > templates. However, I'm having a problem with the images in those > > templates: They're passing through the content handler, and thus getting > > corrupted. > > > > My first thought was to return DECLINED from the content handler if the > > request is not for text/html content; however, since I'm using a > > Location directive, the content_type is always empty since there's no > > direct mapping to an actual image file. I could use an Alias to map the > > URI to the file, but then I wouldn't have the path_info that I'm using > > to call the template. > > > > Since my test code, using path_info, is based on an example from the > > Template Toolkit docs, I feel like I'm probably overlooking something > > basic. So, I'd appreciate it if someone could show me the error of my > > ways. :-) > > > > Here are the relevant chunks of config and code: > > > > from httpd.conf > > --------------- > > ... > > <Location /tt> > > SetHandler perl-script > > PerlHandler Apache::Test::Mod > > PerlSetVar WEBROOT /usr/local/apache/tt/html > > </Location> > > ... > > > > Apache::Test::Mod > > ----------------- > > ... > > sub handler { > > my $r = shift; > > > > # this doesn't work > > #return DECLINED unless $r->content_type eq 'text/html'; > > > > my $WEBROOT = $r->dir_config('WEBROOT') > > or return fail( $r, SERVER_ERROR, "'WEBROOT' not specified" ); > > > > my $file = $r->path_info; > > > > my $vars = { > > content => $r->content_type, > > }; > > > > $r->content_type('text/html'); > > $r->no_cache(1); > > > > my $template = Template->new( { > > INCLUDE_PATH => "$WEBROOT:$WEBROOT/include", > > OUTPUT => $r, > > } ); > > $template->process( $file, $vars, $r) > > or return fail( $r, SERVER_ERROR, $template->error ); > > > > $r->send_http_header(); > > $r->print( $output ); > > > > return OK; > > } > > ... > > > > index.html (test template) > > -------------------------- > > <html> > > <head> > > <title>test</title> > > </head> > > <body> > > <p>content_type: [% content %]</p> > > <p>image: <img src="images/hello.gif"></p> > > </body> > > </html> > > > > > > Thanks. > > > > -Tim > > > > >