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

I am a trainee and have to write a HTML-generating script. I use HTML::Template for that. Right now, I am currently stuck and get the following error: Attempt to set nonexistent parameter 'loop_name' - this parameter name doesn't match any decleration in the template file. What I want to get into the template is something like this: CUSTOMER -> DOMAIN -> MACHINE -> SCHEDULED_EXPORT_TIMES now, every machine can have more than one export a day. So right now I try to iterate through all the values and am stuck at the SCHEDULED_EXPORT_TIMES. Here's the Script:

for my $customer (keys %$bi) { for my $domain (keys %{$bi->{$customer}}) { my %customer_domain_data; $customer_domain_data{CUSTOMER}=$customer; $customer_domain_data{DOMAIN}=$domain; print "$customer\n\t$domain\n"; for my $host (keys %{$bi->{$customer}->{$domain}}) { my $schedule = $bi->{$customer}->{$domain}->{$host}->{BACK +UPCFG}->{EXPORT_SCHEDULE_1}->{VALUE}; if (defined $schedule) { my @schedule_rows_loop =(); my @schedule=split(/,/, $schedule); for my $dif_schedule(@schedule) { my %schedule_rows_data; print "\t\t$dif_schedule\n"; $schedule_rows_data{SCHEDULE}=$dif_schedule; print "\t\t $schedule_rows_data{SCHEDULE}\n"; push (@schedule_rows_loop, \%schedule_rows_data); print Dumper(@schedule_rows_loop); $template->param(SCHEDULE_ROWS => \@schedule_rows_ +loop); } } push (@customer_domain_loop, \%customer_domain_data); $template->param(CUSTOMER_DOMAIN => \@customer_domain_loop +); } } }

And here is the used part in the Template:

<TMPL_LOOP NAME=CUSTOMER_DOMAIN> <tr> <td><TMPL_VAR NAME=CUSTOMER></td> <td><TMPL_VAR NAME=DOMAIN></td> <td> <table style="Width:100%"> <TMPL_LOOP NAME=SCHEDULE_ROWS> <tr> <td><TMPL_VAR NAME=SCHEDULE></td> </tr> </TMPL_LOOP> </table> </td> </tr> </TMPL_LOOP>

I just recently started to learn PERL and I am not that fit in it, so bare with me and my probably silly mistakes!

Replies are listed 'Best First'.
Re: HTML::Template frustrated...
by tangent (Parson) on Jul 14, 2015 at 13:54 UTC
    You are calling $template->param() multiple times within the perl loops, which will overwrite any previous settings. And you are calling $template->param(SCHEDULE_ROWS ...) inside an if block, so if that test returns false it won't be called at all - hence the error.

    Here is a trimmed down version to show the logic required:

    for my $customer (keys %$bi) { for my $domain (keys %{$bi->{$customer}}) { my %customer_domain_data; my @schedule_rows_loop; for my $host (keys %{$bi->{$customer}->{$domain}}) { if (defined $schedule) { for my $dif_schedule(@schedule) { push (@schedule_rows_loop, \%schedule_rows_data); } } } $customer_domain_data{SCHEDULE_ROWS} = \@schedule_rows_loop; push (@customer_domain_loop, \%customer_domain_data); } } $template->param(CUSTOMER_DOMAIN => \@customer_domain_loop);

      thank you! This works exactly like I wanted to :) This is the part which helped me a lot:

      $customer_domain_data{SCHEDULE_ROWS} = \@schedule_rows_loop; push (@customer_domain_loop, \%customer_domain_data);
Re: HTML::Template frustrated...
by 1nickt (Canon) on Jul 14, 2015 at 13:29 UTC

    Have you searched your code for 'loop_name' ? If that term is included inside quotes in the error message, I would think that it referred to an actual string in your code that is causing the error.

    The way forward always starts with a minimal test.

      well yea the 'loop_name' is the loop SCHEDULE_ROWS, I don't get why it doesn't find it

        Exactly. So if the error says

        Attempt to set nonexistent parameter 'loop_name'
        rather than
        Attempt to set nonexistent parameter 'SCHEDULE_ROWS'
        then I would guess that you are passing the literal string 'loop_name' rather than the value of $loop_name (or however you have it stored in your program.)

        That is why I suggested that you search your code for the string 'loop_name' . (Part two of that, left implicit, was to check your quotation/interpolation of $loop_name.)

        But you didn't do that.

        You did insist that "well yea the 'loop_name' is the loop SCHEDULE_ROWS, I don't get why it doesn't find it" , which is not the same as actually examining the value of the variables in your code. See Data::Dumper and The PerlMonks Basic Debugging Checklist.

        (Tip for next time: You should copy and paste inside <code></code> tags the complete error message your program gives you.)

        The way forward always starts with a minimal test.