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

I want to like TT2. I really do. But, I can't seem to make nice with it.
I can get it to run in /cgi-bin , but /cgi-bin/tt2test fails, with a rather annoying error : "file error - main.html: not found". Well, fine. RTFMing. (and if only every module was as well documented!)
Fiddled with paths. Tried turning on absolute paths, relative paths. Neither worked. Spelled out the full path to the file. Tried single and double quotes, left and right leaning slashes in the $file variable, just to be safe.
Broke it down to the following test case :
#!/usr/bin/perl -w use strict; use Template; my $template = Template->new({DELIMITER=>" ", INCLUDE_PATH =>"c:/wwwebster/cgi-bin/tt2 +test/"}) || die "NO soup : $!";; $template->process("main.html")|| die "Template process failed: ", $te +mplate->error(), "\n";
and I still get the same errors. if the same script is in C:/wwwebster/cgi-bin, it'll work fine -- I don't need to set the DELIMITER or INCLUDE_PATH. I'd really like to use tt2, but I seem to be stuck. I'd appreciate any ideas y'all have to offer.

Replies are listed 'Best First'.
Re: Template Toolkit -- looking for files in all the wrong places.
by sutch (Curate) on Apr 02, 2001 at 21:12 UTC
    Here is how I handle it in one of my scripts:

    my $template = Template->new({'INCLUDE_PATH' => '/var/www/template'}); $template->process('home/index.tt2');

    The file is located at:
    /var/www/template/home/index.tt2

    Maybe TT2 operates differently under Windows? The only difference that I can see is that you're INCLUDE_PATH has a trailing slash. I do know that TT2 does not like an initial slash for with the filename or file path in the process method.

Re: Template Toolkit -- looking for files in all the wrong places.
by extremely (Priest) on Apr 03, 2001 at 09:17 UTC
    Open the file yourself first and then hand it the filehandle.
    #untested open TFH, "main.html" or die "Can't open main.html cause $!"; my $template = Template->new() or die "new Template error $!"; $template->process(\*TFH) or die $tt->error(), "\n"; ## or if you hate glob references maybe use IO::File; my $tfh = new IO::File; open($tfh, "main.html") or die "Can't open main.html cause $!"; my $template = Template->new() or die "new Template error $!"; $template->process($tfh) or die $tt->error(), "\n";

    The power of Template is the power of perl, there is more than one way to do things hidden in there. Very cool module. Keep trying with it.

    Also, I'd recommend against putting the templates themselves in a subdirectory of your CGIs. That seems a bit insecure to me. Make a template dir at the same level as the CGIs and the docroot and save yourself some worry.

    --
    $you = new YOU;
    honk() if $you->love(perl)