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

I'm working with CGI::Application and HTML::Template. In my application module, I'm working with a scalar name $output (as in the cpan example). I then call and work with a HTML::Template object. In the end, I need to append the output of the HTML::Template object to the $output scalar. How is it done? I think it is necessary, as CGI::Application expects a single scalar to be returned. Thanks.
my $output = ''; $output .= $q->start_html(-title => 'Widget Search Form'); $output .= $q->p; $output .= $q->start_form(); my $tmpl_obj = $self->load_tmpl('search.tmpl'); $tmpl_obj->param(request); #### THIS DOESN'T WORK #### $output .= print $temp_obj->output; #### NOR DOES THIS #### $tmpl_obj->output(print_to => $output); return $output;

Replies are listed 'Best First'.
Re: Append object output to scalar
by Joost (Canon) on Jun 23, 2005 at 14:01 UTC
      Works, thanks!
Re: Append object output to scalar
by izut (Chaplain) on Jun 23, 2005 at 14:12 UTC
    I use CGI::Application and it works as you expected. I have this method here:
    sub index { my $self = shift; my $template = $self->load_tmpl('index.html'); return $template->output; }
    I checked it's contents with Data::Dumper, and I got this:
    $VAR1 = '<html> <head> <title>Administra\uffff\uffffo VIARS</title> </head> <body> <center> <h1>Consulta de contratos</h1> <form action="viars.cgi" method="post"> <input type="hidden" name="page" value="listar_contratos_action"/> <fieldset style="width: 300px;"> <legend>Filtros</legend> <div style="text-align: left;"> Contrato<br/> <input type="text" name="filtro_contrato" /> <p/> Usu&aacute;rio<br/> <input type="text" name="filtro_usuario" /> <p/> <input type="submit" value="Consultar"/> </div> </fieldset> </form> </center> </body> </html> ';
    Maybe your template is not being rendered. izut
      Well, as I said before, your template is not being rendered :)
Re: Append object output to scalar
by blazar (Canon) on Jun 23, 2005 at 14:07 UTC