Re: [htmltmpl] Templates with template loops within templates
Brought to you by:
samtregar
From: Mathew R. <mat...@re...> - 2004-12-16 23:54:39
|
Hi Eric, It sounds like you have hit the dreaded "top level param, not referenced = before use in template loop, so I'll just do nothing" bug... try this = somewhere before your first TMPL_LOOP (say at the top of the file), in = your first template: <!-- H::T BUG: <TMPL_VAR URL_BASE> --> which _should_ do absolutely nothing useful/harmful to the html output. = However, it will result in H:T actually getting a reference to the = URL_BASE variable. What you were expecting to happen (ie template variable used in some = child template, when being set at the top-level), is what most people = expect to happen... In my own templates, I have also hit this problem. This bug is a result of how H::T handles TMPL_LOOP invocations... it = basically does a recursive call of itself, passing the known params from = the previous instance, into this new invocation. Since the previous = invocation hasn't referenced the TMPL_VAR, that value isn't passed into = the TMPL_LOOP invocation. Hope this helps, Mathew ----- Original Message -----=20 From: "Eric Frazier" <er...@dm...> To: <htm...@li...> Sent: Friday, December 17, 2004 10:39 AM Subject: [htmltmpl] Templates with template loops within templates > Hi, >=20 > Great subject line huh? :) >=20 > Ok we have a template. > Inside that template we load in from a database a template with its = own=20 > vars which makes use of a template loop. > In that second template we have a var called URL_BASE which is the = base=20 > path. It works inside the second template, except for within the = template=20 > loop output. >=20 >=20 > So imagine we already have template object: $template (it by the way = has a=20 > var called URL_BASE also that I thought would be passed down to this = inside=20 > template as well) >=20 > my $shipping_temp =3D=20 > $config->getShipping_temp($self->param('DEFAULT_PRODUCT')); ## returns = > array ref > my $ship_list_hash =3D $config->getShipping_list($instance,$dom_int); >=20 > $template->param(SHIPPING =3D> '1'); ## part of the top level template >=20 > my $shipref =3D \$shipping_temp->[0]; >=20 > my $ship_html =3D HTML::Template->new( scalarref =3D> $shipref, > die_on_bad_params =3D>0); > my @loop_values =3D (); > my $num_options =3D keys(%$ship_list_hash); >=20 > foreach my $key( keys(%$ship_list_hash) ){ >=20 > my %inside_hash =3D ('S_ICON' =3D>=20 > $ship_list_hash->{$key}{'courier_icon_url'}, > 'S_COURIER' =3D> = $ship_list_hash->{$key}{'courier_name'}, > 'S_METHOD' =3D> = $ship_list_hash->{$key}{'courier_method'} , > 'S_METHOD_ID' =3D> = $ship_list_hash->{$key}{'ship_method_id'}, > 'S_COST' =3D>=20 > $ship_list_hash->{$key}{'shipping_cost'}=20 >=20 > ); >=20 > if ($shipping_temp->[1] eq=20 > $ship_list_hash->{$key}{'ship_method_id'}){ > $inside_hash{'DEFAULT'} =3D 'Checked'; > } >=20 > if ($num_options < 2){ > $inside_hash{'DEFAULT'} =3D 'Checked'; > } >=20 >=20 > push(@loop_values,\%inside_hash); >=20 > } > $ship_html->param(URL_BASE =3D> = $self->param('URL_BASE')); ##=20 > the problem var > $ship_html->param(SHIP_LOOP =3D> \@loop_values); >=20 >=20 > my $tmpout =3D $ship_html->output(); >=20 >=20 >=20 > Below is the raw HTML output produced, notice the spacer.gif has a = full url=20 > where the ups_2D.gif which comes from the loop does not. >=20 > I was a little confused to start off with because I thought the = presence of=20 > the URL_BASE in the second template would be parsed as a result of = being=20 > set in the original top level template. So not only does that not seem = to=20 > be happening, but also when setting the var again in the second = template it=20 > is not working inside the template loop. So my first question, is this = the=20 > way HTML::Template should be working? I didn't expect this problem. = The=20 > next question of course is how can I get this var to be parsed inside = the=20 > loop? >=20 > Using the current versions of both HTML::Template and CGI::Application >=20 > Please let me know if this is enough info or too much, I wanted to = give as=20 > much detail as I could because I found it hard to explain what I am = doing=20 > with just words. >=20 >=20 > Thanks, >=20 > Eric >=20 >=20 > <!--Start of Shipping type Section=20 > --> > <TABLE WIDTH=3D700 class=3D"bord" BORDER=3D0 CELLPADDING=3D2 = CELLSPACING=3D0=20 > align=3D"center"> > <TR>=20 >=20 > <TD class=3D"bord" align=3D"center"><span=20 > class=3D"title">Shipping Method</span></TD> > </TR>=20 >=20 > <TR>=20 >=20 > <TD>=20 >=20 > <!--second color=20 > table--> > <TABLE WIDTH=3D700 class=3D"main" BORDER=3D0 = > CELLPADDING=3D10 CELLSPACING=3D0 align=3D"center"> > <TR>=20 >=20 > <TD class=3D"main"=20 > align=3D"center"> > <!--pieces=20 > table--> > <TABLE WIDTH=3D95% BORDER=3D0 = CELLPADDING=3D0=20 > CELLSPACING=3D0 align=3D"center"> > <tr>=20 >=20 > <td><IMG=20 > SRC=3D"https://www.host.com/htmltemp_consol/images/spacer.gif" = WIDTH=3D10=20 > HEIGHT=3D5></TD> > </tr>=20 >=20 > <tr> > <td> > <table align=3D"center"> > <tr> >=20 >=20 >=20 > <label=20 > for=3D"ship4">=20 >=20 > <TD width=3D15 align=3D"right"><input type=3Dradio = id=3D"ship4"=20 > name=3D"ship_option" value=3D"4" Checked></TD> > <TD width=3D65 class=3D"boxfields" align=3D"center" = valign=3D"top"> > <img src=3D"images/shipping/ups_2D.gif" alt=3D"LEM = Domestic=20 > "><br><b>$10.00</b></TD> > </label> >=20 > </tr> > </table> > </td> > </tr>=20 >=20 > <tr>=20 >=20 > <td><IMG=20 > SRC=3D"https://www.host.com/htmltemp_consol/images/spacer.gif" = WIDTH=3D10=20 > HEIGHT=3D5></TD> > </tr>=20 >=20 > </table>=20 >=20 > <!--end of pieces=20 > table--> > </td>=20 >=20 > </tr>=20 >=20 > </table>=20 >=20 > <!--end of second color=20 > table--> > </TD>=20 >=20 > </TR>=20 >=20 > </table>=20 >=20 > <!--end of Shipping type Section--> >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real = users. > Discover which products truly live up to the hype. Start reading now.=20 > http://productguide.itmanagersjournal.com/ > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |