I find that when I separate my presentation and code with Template Toolkit, I often find that I've goofed in trying to access my data correctly within the template. This little snippet generates a nice, pretty-printed output directly to the template.
To use this, I place the following line of code right before the closing body tag in the template:
<pre>[% dump %]</pre>
use strict; use CGI; use Template; use constant DEBUGGING => 1; $|++; my $query = CGI::->new; my $template = Template->new( { INCLUDE_PATH => '..\templates', ABSOLUTE => 1 } ); my $data = { one => 1, two => 'foo', bar => [qw/ baz qux Ovid/] }; if ( DEBUGGING ) { require Data::Dumper; require HTML::Entities; $data->{ dump } = HTML::Entities::encode_entities( Data::Dumper::Dumper( $data ) + ); } print $query->header; $template->process( 'some.tmpl', $data ) or dienice $template->error();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Debugging Template Toolkit
by merlyn (Sage) on Feb 21, 2002 at 01:35 UTC |