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

Fellow Monasterians

<disclaimer>This is more about a Perl module than Perl.</disclaimer>

I'm having problems getting <base href> to work in a particular H::T scenerio. I've tried a number of things, but I feel like I'm hunting gophers.

First, here's my file layout:

In root: index.cgi [cgi-bin] -> contact.pl [pages] -> contact.tmpl -> topnav.tmpl -> thankyou.tmpl

Now, here's the salient code

INDEX.CGI: $template = HTML::Template->new(filename => 'pages/contact.tmpl'); CONTACT.TMPL: <base href="http://132.321.33.321/" /> <tmpl_include name="pages/topnav.tmpl"> <form action="../cgi-bin/contact.pl"...> TOPNAV.TMPL ... <li><a href="?p=6">LINKS</a></li> ...

'Base href' works in the initial call of contact.tmpl from index.cgi. But if contact.tmpl is evoked from cgi-bin/contact.pl, e.g.,if errors are found in validation and I'm redisplaying the form with 'associate', H::T returns an error that it can't find my "includes".

So, I dropped the <base href> and went to relative paths. It worked fine until I called thankyou.tmpl from contact.pl after the form is processed. The navigation is messed up because it's trying to do cgi-bin/contact.pl?p=6.

I tried:

$template->param(HOME => $ENV{HOME}); $template->param(PATH => $ENV{PATH});

thinking that had something to do with it. But the "includes" error occurs in the

$template = HTML::Template->new(filename => '../pages/contact.tmpl');

Bottomline, is there a reason base href does not work when calling a .tmpl file from my cgi-bin/contact.pl? Or what path convention am I not getting? Thanks all!


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re: Path problems using HTML::Template
by perrin (Chancellor) on Aug 29, 2005 at 20:13 UTC
    You seem to be confused about URLs and template paths. A base href tag will alter where your relative links go, but will not affect the include path for HTML::Template in any way. What will affect it is your current working directory, which is different when running /index.cgi than it is when running /cgi-bin/contact.pl. To use the same template from different directories, you either specify a different path or use absolute paths.

      Perfect perrin. I got it.

      Once I realized that <base href> is not related to H::T paths, I was fine. ALSO, I was confused about absolute paths. I re-read the manpage for H::T and it states:

      The file specified can be an absolute path (beginning with a '/' under Unix, for example)

      /usr/www/users/acme/pages/ NOT http://213.34.321.23/pages/

      So, thanks.


      —Brad
      "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: Path problems using HTML::Template
by InfiniteSilence (Curate) on Aug 29, 2005 at 20:31 UTC
    Not sure why you don't have all .cgi files in your cgi-bin directory, but that is another matter. You might try to tighten up your anchors if you are going to assume that they are relative, like so:
    TOPNAV.TMPL ... <li><a href="THENAMEOFTHESCRIPTIWOUDLLIKETORUN.pl?p=6">LINKS</a></li>

    Celebrate Intellectual Diversity