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

Hi. I'm trying to work through the template toolkit tutorial and can't get the examples to work. Here's my main code:
#!/usr/bin/perl -w use strict; use Template; use CGI qw/:standard/; use CGI::Carp qw/fatalsToBrowser/; $| = 1; print header; my $file = '/templates/userinfo.html'; my $vars = { 'version' => 3.14, 'days' => [ qw( mon tue wed thu fri sat sun ) ], 'worklist' => \&get_user_projects, 'cgi' => CGI->new(), 'me' => { 'id' => 'abw', 'name' => 'Andy Wardley', }, }; sub get_user_projects { my $user = shift; my @projects = qq/ Foo Bar Baz /; return \@projects; } my $template = Template->new({ INCLUDE_PATH => '/templates/includes', PRE_PROCESS => 'config', }); $template->process($file, $vars) # This is line 33 || die $template->error();
When I try to run this it says
file error - /templates/userinfo.html: absolute paths are not allowed +(set ABSOLUTE option) at C:\Inetpub\wwwroot\cgi-bin\userinfo.cgi line 33.
When I change the file to a relative path, it says
file error - ../templates/userinfo.html: relative paths are not allowe +d (set RELATIVE option) at C:\Inetpub\wwwroot\cgi-bin\userinfo.cgi line 32.
Why does it say that I can't use absolute or relative paths? I didn't know there were any other types. Grr...

This is the file structure, if it matters.


wwwroot ---- cgi-bin
         |
         |
         \-- templates ---- includes
I have userinfo.html in the templates folder and the header and footer files in the includes folder.

Replies are listed 'Best First'.
Re: Using Template toolkit
by chipmunk (Parson) on May 11, 2001 at 20:08 UTC
    Well, did you try setting the ABSOLUTE and/or RELATIVE options, as suggested in the error messages that you quoted?
    my $template = Template->new({ INCLUDE_PATH => '/templates/includes', PRE_PROCESS => 'config', ABSOLUTE => 1, # (may want to pick one or the other RELATIVE => 1, # instead of using both) });
      I did after I saw what you wrote. Now it just gives me file not found messages, even though I know they are there. Is there any way I can get it to print the full path with drive letter that its searching?
Re: Using Template toolkit
by Masem (Monsignor) on May 11, 2001 at 20:01 UTC
    I'm guessing you are using a Win32 machine based on your error messages. You probably need to change the way you are referencing files to match what Win32 expects (eg reverse the slashes).


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      I thought that shouldn't matter, but I went ahead and reversed them. Now, it says
      file error - \templates\userinfo.html: not found at C:\Inetpub\wwwroot\cgi-bin\userinfo.cgi line 33.
      It doesn't matter if I use an absolute or relative path. I still get the message.I have double checked that the files and folders are there and spelled correctly. Does TT have restrictions on where it will look for files? I even tried specifying the drive letter and I get this weird message
      file error - no providers for template prefix 'C' at C:\Inetpub\wwwroot\cgi-bin\userinfo.cgi line 33.
      The TT at http://www.template-toolkit.org/docs/plain/Tutorial/Tutorial.html doesn't mention any of this stuff. Is there another tutorial somewhere on using this on Win systems? :(

      By the way, thanks for helping.

        I'm not sure as I haven't used TT2 on a Win32 system, however, I do know that TT2 has a good mailing list with archives available near that URL you have above; take a look through there and see if anyone has already addressed using TT2 on Win32. IIRC, TT2 is simplying using the standard perl open and friends to do it's job, so you'd have to stick to how file operations work on Win32.
        Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: Using Template toolkit
by Anonymous Monk on May 11, 2001 at 20:37 UTC
    I found most of the problem. It seems that the include path should point to the base documents that I include, no to the header and footer files.
    INCLUDE_PATH => '..\templates',
    I have other problems, but I think I can work around those. Thanks everyone.