[Templates] Findng Errors in Template files

michael south msouthmi at gmail.com
Wed Jan 9 20:31:08 GMT 2008


On Jan 9, 2008 2:59 PM, David Martin <designs at nolaflash.com> wrote:

>  Hello,
>
>
>
> I have a template with an error in it that I just can't seem to track
> down.  I seem to recall from years ago that there is a way to tell the TT
> compiler to compile the template file and in that way discover the line
> number where it breaks?
>
>
>
> Is there a way to do that?
>
> You mean like this:

my $tt = Template->new();
$tt->process('template.tt') || die $tt->error();


I tested with the following in template.tt:

[% template.name %]
[% IF foo %]

and it gave me:

> perl foo.pl
file error - parse error - template.tt line 2: unexpected end of input

You can call the parser directly, using the text of the template, like this:

use Template::Parser;
use Data::Dumper;
use File::Slurp;

my $tt_code = File::Slurp::read_file('./template.tt');
my $parser = Template::Parser->new();
my $perl_code = $parser->parse($tt_code);
die $parser->error() unless defined $perl_code;
print Dumper $perl_code;

but it will just give you the same error.

>
>
> Thanks for any help,
>
>
>
> David Martin
> NolaFlash.com <http://www.nolaflash.com/>
> Web Design, Programming and Hosting
>
> 4600 S Tonti St
> NO LA 70125
> 504.583.3755
>
> <http://www.nolaflash.com/>
>
>
>
> _______________________________________________
> templates mailing list
> templates at template-toolkit.org
> http://mail.template-toolkit.org/mailman/listinfo/templates
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20080109/a165e220/attachment.htm 


More information about the templates mailing list