Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Template Toolkit example getting blank output page

by Anonymous Monk
on Sep 24, 2012 at 10:38 UTC ( #995346=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have tried below example using Template toolkit, but display page is getting blank.
header.html, footer.html and main.html are kept under /home/userone/public_html/template directory.
Can anyone tell me why I am getting blank page when I call process_template.pl script.
Operating System : Linux
Perl Version : 5.10.1
Apache version 2.2.22

header.html <html> <head> <title>[% title %]</title> </head> <body bgcolor="#ffffff"> <h1>[% title %]</h1> *********************************************** footer.html <div align="center"> [% copyright %] </div> </body> </html> *************************************************** main.html [% PROCESS header title="Some Interesting Links" %] <p> Here are some interesting links: <ul> [% FOREACH link = weblinks %] <li><a href="[% link.url %]">[% link.title %]</a></li> [% END %] </ul> </p> [% PROCESS footer %] *************************************************** process_template.pl #!/usr/bin/perl print "Content-Type: text/html\n\n"; use strict; use warnings; use Template; # create template processor my $tt = Template->new({ INCLUDE_PATH => [ '/home/userone/public_html/template', ], PRE_PROCESS => 'header', POST_PROCESS => 'footer', }); # define data my $data = { copyright => '&copy; 2002 Andy Wardley', weblinks => [ { url => 'http://perl.apache.org/', title => 'Apache/mod_perl', }, { url => 'http://tt2.org/', title => 'template Toolkit', }, ] }; $tt->process('main.html',$data) || die $tt->error(); ********************************

could you please help me to get an output page

Thanks

Comment on Template Toolkit example getting blank output page
Download Code
Re: Template Toolkit example getting blank output page
by marto (Chancellor) on Sep 24, 2012 at 10:57 UTC

    See the various examples in the Template documentation for the Process method. You need to define how you'd like it to output. For example:

    my $output=''; $tt->process('main.html',$data, \$output) || die $tt->error(); print $output;
Re: Template Toolkit example getting blank output page
by grumbert (Scribe) on Sep 24, 2012 at 10:59 UTC

    Without looking at your TT code, it may be worth looking at your apache error & httpd logs. Typically errors get put in either of those logs and may provide valuable information on troubleshooting.

    Sorry if this is all rather obvious but it would be my first step in figuring out what's happening.

Re: Template Toolkit example getting blank output page
by sundialsvc4 (Monsignor) on Sep 24, 2012 at 12:59 UTC

    Use a client-side debugger such as Firebug, or the various developer-tools built into most browsers, to LQQK at the HTML code that your application is actually sending.   Only in this way will you actually know.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://995346]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-08-29 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (281 votes), past polls