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

Hi Monks!

I need to load a template that is in a module to the main template in the main.pl file.
Question is, if this is the way to do it, I am getting this error :

"Can't call method "output" on an undefined value"

I do have values in "\@rows", I might be passing it wrong?
Here is the code to show, to illustrate my saying:

main.pl
use strict ; use warnings ; use CGI ; use CGI::Carp qw(fatalsToBrowser); use Data::Dumper ; use Data::Dump 'pp'; use InfoD; use HTML::Template; my $q = CGI->new; start(); sub start { my $return_val_from_tables = tables(); # Main Template my $main_tmpl = HTML::Template->new(filename => 'templates/main.tmpl' +, die_on_bad_params => 0,); # load values into the main template my $name = "Proto"; $main_tmpl->param( NAME => $name, STUFF => 'TEST', LOAD => $return_val_from_tables->output(), ); print $q->header, $main_tmpl->output; }


InfoD.pm
sub tables { my @rows = ( ... ) ; # Load new template to add to main template later my $table_tmpl = HTML::Template->new(filename => 'templates/table.tmp +l', die_on_bad_params => 0,); #Load these values into the template $table_tmpl->param( DATA => \@rows, ); # Load this template into main template my $table_load = $table_tmpl->output(); return $table_load; } 1;

Thank you for helping out!

Replies are listed 'Best First'.
Re: Return value to use in HTML::Template
by poj (Abbot) on Jan 08, 2016 at 22:16 UTC

    The return from tables() is

    $table_load = $table_tmpl->output(); return $table_load;

    so why have ->output() again here ?

    LOAD => $return_val_from_tables->output(),
    poj
Re: Return value to use in HTML::Template
by Anonymous Monk on Jan 08, 2016 at 21:52 UTC
    That error means that this is undef  my $return_val_from_tables = tables();