Rather than using print statements, copy all of your method's output into a variable and return the content of that variable to template toolkit.
 
IE:
 
sub generate_my_table() {
 
    my $output = '<table><tr><td></td></tr></table>';
 
    return $output
}
 
Note that this is not ideal and you should let template toolkit generate the table for you.
 
 
- Jm
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Matthew Haines
Sent: Monday, April 12, 2004 2:25 PM
To: [EMAIL PROTECTED]
Subject: [Templates] Incorporating existing sub's with print statements into templates

I am trying to slowly migrate an application to TT and have run into the following problem for which I hope there is an easy and standard solution someone can point me to.
 
I have a large number of existing subroutines that print out HTML.  Usually these subroutines generate the HTML for a specific table on the page.  In many cases I don't want to convert them to templates immediately.  Rather, I'm trying to undertake a slow migration in which I first convert the overall page layout to templates and then deal with these specific table generators later when other reasons force me to work on that code.
 
I tried doing a callback like this:
    [% CALL generate_my_table(dbh, some_parameters) %]
 
Here "generate_my_table" is a perl sub and dbh is the standard database handle.  The &generate_my_table sub is full of print statements that print straight to STDOUT.  Unfortunately everything it prints appears *before* anything generated by TT.  How can I get the output to be embedded in the TT output at the right place?
 
Thanks,
 
Matthew

Reply via email to