Hey Andy, great facility. Wondering if it wouldn't be more consistent with Perl/TT
syntax to say this though:
[% USE DEBUG %]
[% foo = 10 %](set foo)
[% NO DEBUG %]
[% foo %]
[% USE DEBUG('<!-- $file line $line: $text -->') %]
[% foo %]
This does make it look like a plug-in, but modules and pragmas use the same syntax in
perl source, so it could be good enough for us
too :)
-Stephen
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Andy Wardley
Sent: Friday, May 03, 2002 10:30 AM
To: [EMAIL PROTECTED]
Subject: [Templates] The DEBUG directive.
I've added some better debugging facilities to TT.
If you set the DEBUG option on, the parser will now generate debugging
information for each directive encountered. When the template is processed,
this information is added to the template output.
my $tt = Template->new( DEBUG => 1 );
$tt->process('the/foo/file') || die $tt->error();
If you process this file:
[% foo = 10 %](set foo)
Hello World
[% foo %]
Then the output generated is:
## the/foo/file line 1 : [% foo = 10 %] ##
(set foo)
Hello World
## the/foo/file line 3 : [% foo %] ##
10
Each directive generates a comment indicating where it is in the
file and showing the directive text.
You can change the format of the comment like so (note single quotes to
avoid interpolation of $file, $line, $text):
my $tt = Template->new({
DEBUG => 1,
DEBUG_FORMAT => '<!-- $file line $line: [% $text %] -->'
});
and instead you get output like this:
<!-- the/foo/file line 1 : [% foo = 10 %] -->
(set foo)
Hello World
<!-- the/foo/file line 3 : [% foo %] -->
10
If you prefer, you can use the DEBUG directive to enable/disable
debugging on a per-file basis and to define a new format.
[% DEBUG on %]
[% foo = 10 %](set foo)
[% DEBUG off %]
[% foo %]
[% DEBUG on %]
[% DEBUG format '<!-- $file line $line: $text -->' %]
[% foo %]
This generates output something like:
## the/foo/file line 2 : [% foo = 10 %] ##
(set foo)
## the/foo/file line 4 : [% DEBUG off %] ##
10
## the/foo/file line 8 : [% DEBUG format '<!-- $file line $line: $text -->' %] ##
<!-- the/foo/file line 9: foo -->10
This functionality is in the CVS repository. To be released as a developer
release RSN.
A
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates