http://www.perlmonks.org?node_id=840781

Perobl has asked for the wisdom of the Perl Monks concerning the following question:

I am a TT2 newbie. I'm using TT2 to create dynamic web pages using CGI Perl. I have set up a simple site to test my configuration running locally on Apache2. For the most part, everything is working great.

However, my images and external CSS files can't be accessed by my dynamic pages. I have my image files saved to assets/images inside my site's root directory: /Users/mysilmaril/Sites/WIW/assets/images

Likewise, my CSS file is saved to /Users/mysilmaril/Sites/WIW/css

This is all very standard stuff. When I access my CGI script from an HTML page (via a form) it utilizes TT2 to generate a wrapper and then it generates some simple text inside the [% content %] directive. This part is working great.

The images and external CSS can't be found because the dynamic page is being generated by the CGI script in the cgi-bin directory. I could hard code relative paths into my wrapper to solve this problem, but this is not an idea solution for me.

I'm sure there is a way to solve this problem through TT2's configuration, but I can't figure out how to do it. I'm pasting my test CGI script below:

#!/usr/local/bin/perl use strict; use warnings; use Template; use CGI; my $cgi = CGI->new(); my $tt = Template->new({ INCLUDE_PATH => [ '/Users/mysilmaril/Sites/WIW/templates/src', '/Users/mysilmaril/Sites/WIW/templates/lib/site', '/Users/mysilmaril/Sites/WIW/templates/lib/config', '/Users/mysilmaril/Sites/WIW/cgi-bin', '.', ], WRAPPER => 'wrapper', }); my $input = 'cgiparams.tt'; my $vars = { cgi => $cgi, }; print $cgi->header; $tt->process($input, $vars) || die $tt->error();
My template file:
<tr> <td colspan="2" align="center" height="200"> <ul> [% FOREACH p = cgi.param -%] <p><b>[% p %]:</b>&nbsp;[% cgi.param(p) %]</p> [% END -%] </ul> </td> </tr>
My wrapper is s standard HTML page (header, footer). I'll paste the HTML for my CSS here as an example:
<link rel="stylesheet" type="text/css" href="css/wiw.css" />
If I change href="wiw.css" to href="../css/wiw.css" it will load fine, but this is what I want to avoid doing. Can I configure this in TT2? Thanks!