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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.