Thread: [htmltmpl] LOOPING error [code included]
Brought to you by:
samtregar
From: Robert H. <si...@gm...> - 2006-12-05 14:21:10
|
Error executing run mode 'display_employee_page': HTML::Template->output() : fatal error in loop output : HTML::Template : Attempt to set nonexistent parameter 'labor_category' - this parameter name doesn't match any declarations in the template file : (die_on_bad_params => 1) at C:/Perl/site/lib/HTML/Template.pm line 2997 at lib//Trakker.pm line 142 at D:/www/DEV/test/index.cgi line 14 I have 1 SQL call bringing back 3 values (BILL_CODE, LABOR_CATEGORY, LABOR_CATEGORY_DESCRIPTION). I have 3 separate loops using each of those. I am converting something from TT->HT and this works fine in TT. Is there something about how HT loops that is biting me? I am sure "I" am forgetting something. Here is the SQL sub: sub _get_employee_info { my $self = shift; my $sth = $self->dbh->prepare( select_employee_info() ); $sth->execute; my $rs = $sth->fetchall_arrayref( { BILL_CODE => 1, LABOR_CATEGORY => 1, LABOR_CATEGORY_DESCRIPTION => 1, } ); return $rs; } Here is the CA+HT runmode sub: sub display_employee_page : Runmode { my $self = shift; my $errs = shift; my $q = $self->query; my $template = $self->load_tmpl( 'addemployee.tmpl' ); my $employee_info = $self->_get_employee_info(); $template->param( MODDATE => '04-Dec-2006', VERSION => $VERSION, EMPLOYEE_INFO => $employee_info, ); $template->param($errs) if $errs; return $template->output(); } Here is the TEMPLATE form: <form name="tasks" action="" method="post"> <table id="formcontent" summary="main form for task input"> <tr> <td class="labelcell">Last Name:</td> <td> <input type="text" name="last_name" size="25" /><TMPL_VAR err_last_name> </td> </tr> <tr> <td class="labelcell">First Name:</td> <td> <input type="text" name="first_name" size="25" /><TMPL_VAR err_first_name> </td> </tr> <tr> <td class="labelcell">Billing Code:</td> <td> <select name="bill_code"> <option value=""></option> <TMPL_LOOP NAME=EMPLOYEE_INFO> <option value="<TMPL_VAR NAME=BILL_CODE>"><TMPL_VAR NAME=BILL_CODE></option> </TMPL_LOOP> </select><TMPL_VAR err_bill_code> </td> </tr> <tr> <td> </td> <td>- or -</td> </tr> <tr> <td class="labelcell">Add Code:</td> <td> <input type="text" name="add_bill_code" size="10" /><TMPL_VAR err_bill_code_or_add_bill_code> </td> </tr> <tr> <td class="labelcell">Labor Category:</td> <td> <select name="labor_category"> <option value=""></option> <TMPL_LOOP NAME=EMPLOYEE_INFO> <option value="<TMPL_VAR NAME=LABOR_CATEGORY>"><TMPL_VAR NAME=LABOR_CATEGORY></option> </TMPL_LOOP> </select><TMPL_VAR err_labor_category> </td> </tr> <tr> <td> </td> <td>- or -</td> </tr> <tr> <td class="labelcell">Add Category:</td> <td> <input type="text" name="add_labor_category" size="9" /><TMPL_VAR err_add_labor_category> </td> </tr> <tr> <td class="labelcell">Description:</td> <td> <select name="labor_category_description"> <option value=""></option> <TMPL_LOOP NAME=EMPLOYEE_INFO> <option value="<TMPL_VAR NAME=LABOR_CATEGORY_DESCRIPTION"><TMPL_VAR NAME=LABOR_CATEGORY_DESCRIPTION></option> </TMPL_LOOP> </select><TMPL_VAR err_labor_category_description> </td> </tr> <tr> <td> </td> <td>- or -</td> </tr> <tr> <td class="labelcell">Add Description:</td> <td> <input type="text" name="add_labor_category_description" size="30" /><TMPL_VAR err_add_labor_category_description> </td> </tr> <tr> <td> </td> <td> <input type="submit" value="Save Employee" class="formbutton" /> </td> </tr> </table> </form> |
From: Roger B. W. <ro...@fi...> - 2006-12-05 14:23:59
|
On Tue, Dec 05, 2006 at 09:20:40AM -0500, Robert Hicks wrote: >I have 3 separate loops using each of those. I am converting something >from TT->HT and this works fine in TT. Is there something about how HT >loops that is biting me? I am sure "I" am forgetting something. In my experience, multiple loops of the same name will throw up this problem - only the first loop gets checked. The simplest solution is to set die_on_bad_params to zero. Roger |
From: Michael P. <mp...@pl...> - 2006-12-05 14:46:29
|
Roger Burton West wrote: > On Tue, Dec 05, 2006 at 09:20:40AM -0500, Robert Hicks wrote: > >> I have 3 separate loops using each of those. I am converting something >>from TT->HT and this works fine in TT. Is there something about how HT >> loops that is biting me? I am sure "I" am forgetting something. > > In my experience, multiple loops of the same name will throw up this > problem - only the first loop gets checked. The simplest solution is to > set die_on_bad_params to zero. He's right. H::T isn't very thorough when checking for the existence of variables in loops if the same loop is used more than once. Setting die_on_bad_params to false will let you get around this problem, but that causes problems if you wanted strict templates in the first place. Fixing this has been one of my TODOs for a while... Stupid $work and $life :) -- Michael Peters Developer Plus Three, LP |
From: Benjamin W. <war...@sb...> - 2006-12-06 03:18:17
|
On Dec 5, 2006, at 9:44 AM, Michael Peters wrote: > Setting die_on_bad_params to false will let you get around this > problem, but that causes > problems if you wanted strict templates in the first place. You can also get around the problem without disabling variable-name checking for the rest of the template, albeit in a remarkably hackish way: just add the appropriate version of <TMPL_IF NAME="my_missing_var"></TMPL_IF> on the inside of the loop that doesn't actually make use of the variable, and it will show up as a valid variable for both loops. --Ben Warfield |
From: Robert H. <si...@gm...> - 2006-12-05 15:03:29
|
Michael Peters wrote: > > Roger Burton West wrote: >> On Tue, Dec 05, 2006 at 09:20:40AM -0500, Robert Hicks wrote: >> >>> I have 3 separate loops using each of those. I am converting something >> >from TT->HT and this works fine in TT. Is there something about how HT >>> loops that is biting me? I am sure "I" am forgetting something. >> In my experience, multiple loops of the same name will throw up this >> problem - only the first loop gets checked. The simplest solution is to >> set die_on_bad_params to zero. > > He's right. H::T isn't very thorough when checking for the existence of > variables in loops if the same loop is used more than once. Setting > die_on_bad_params to false will let you get around this problem, but that causes > problems if you wanted strict templates in the first place. > > Fixing this has been one of my TODOs for a while... Stupid $work and $life :) > Forgive me if this is ignorant, I am not far along the path: I have this: my $rs = $sth->fetchall_arrayref( { BILL_CODE => 1, LABOR_CATEGORY => 1, LABOR_CATEGORY_DESCRIPTION => 1, } ); And I have this: my $employee_info = $self->_get_employee_info(); Can I not reference those in separate calls: $template->param( one => $employee_info[0], # not sure what the construct would be two => $employee_info[1], three => $employee_info[2], ), If not how do I set that param to 0 in a CA fashion? Robert |
From: Robert H. <si...@gm...> - 2006-12-06 13:44:00
|
I found where to put the "die_on_bad_params". Seems a shame to have to do that. Robert |