Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!
I am changing HTML::Template to Template Toolkit in my code, but I am stuck where I am trying to append data, its OK done with HTML:Template, but now I have to use TT. How could I do the same I did here using HTML::Template to work with TT, has anyone done something like that before?
#!/usr/bin/perl -w use strict; use Template; ... my $template = Template->new( ); my $temp_data = {}; # set variales for template ... # here is how I did for HTML::Template #$template->param(my_date => $date); #$onscreen .= $template->output; # process template with tt $temp_data->{'my_date'} = $date; $onscreen .= $template->process('screen.html', $temp_data) || di +e $template->error( ); ... $onscreen .="</table>";
Thanks for the Help!

Replies are listed 'Best First'.
Re: Appending to Template Toolkit
by Corion (Patriarch) on Mar 07, 2011 at 19:48 UTC

    Have you looked at the Template::process documentation? It tells you how to do what you want.

      I couldn't find anything that allowed me to append to a line like this:
      $onscreen .= $template->process('screen.html', $temp_data) || di +e $template->error( );
      I need to bring this piece of html file with the $date in it into $onscreen so the rest of the code finished its processing.

        Then read the section again. Maybe searching for the word "append" helps. I'm not sure how I could tell things clearer than the documentation already does, which is why I'm pointing you to it instead of regurgitating it here.

        One note - you will probably run into precedence issues with || vs. or. See perlop for more information.

        --MidLifeXis