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!

In reply to Template Toolkit Question by Perobl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.