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 ----- 
From: "Eric Frazier" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, December 17, 2004 10:39 AM
Subject: [htmltmpl] Templates with template loops within templates


> Hi,
> 
> Great subject line huh? :)
> 
> Ok we have a template.
> Inside that template we load in from a database a template with its own 
> vars which makes use of a template loop.
> In that second template we have a var called URL_BASE which is the base 
> path. It works inside the second template, except for within the template 
> loop output.
> 
> 
> So imagine we already have template object: $template (it by the way has a 
> var called URL_BASE also that I thought would be passed down to this inside 
> template as well)
> 
> my $shipping_temp = 
> $config->getShipping_temp($self->param('DEFAULT_PRODUCT')); ## returns 
> array ref
> my $ship_list_hash = $config->getShipping_list($instance,$dom_int);
> 
> $template->param(SHIPPING => '1'); ## part of the top level template
> 
> my $shipref = \$shipping_temp->[0];
> 
> my $ship_html = HTML::Template->new( scalarref => $shipref,
>                                         die_on_bad_params =>0);
> my @loop_values = ();
> my $num_options = keys(%$ship_list_hash);
> 
>          foreach my $key( keys(%$ship_list_hash) ){
> 
>            my %inside_hash = ('S_ICON'      => 
> $ship_list_hash->{$key}{'courier_icon_url'},
>                 'S_COURIER'   => $ship_list_hash->{$key}{'courier_name'},
>                  'S_METHOD'    => $ship_list_hash->{$key}{'courier_method'} ,
>                  'S_METHOD_ID' => $ship_list_hash->{$key}{'ship_method_id'},
>                  'S_COST'      => 
> $ship_list_hash->{$key}{'shipping_cost'} 
> 
>                     );
> 
>            if ($shipping_temp->[1] eq 
> $ship_list_hash->{$key}{'ship_method_id'}){
>                  $inside_hash{'DEFAULT'} = 'Checked';
>            }
> 
>            if ($num_options < 2){
>                  $inside_hash{'DEFAULT'} = 'Checked';
>            }
> 
> 
>            push(@loop_values,\%inside_hash);
> 
> }
>          $ship_html->param(URL_BASE      => $self->param('URL_BASE'));   ## 
> the problem var
>          $ship_html->param(SHIP_LOOP => [EMAIL PROTECTED]);
> 
> 
>          my $tmpout = $ship_html->output();
> 
> 
> 
> Below is the raw HTML output produced, notice the spacer.gif has a full url 
> where the ups_2D.gif which comes from the loop does not.
> 
> I was a little confused to start off with because I thought the presence of 
> the URL_BASE in the second template would be parsed as a result of being 
> set in the original top level template. So not only does that not seem to 
> be happening, but also when setting the var again in the second template it 
> is not working inside the template loop. So my first question, is this the 
> way HTML::Template should be working? I didn't expect this problem. The 
> next question of course is how can I get this var to be parsed inside the 
> loop?
> 
> Using the current versions of both HTML::Template and CGI::Application
> 
> Please let me know if this is enough info or too much, I wanted to give as 
> much detail as I could because I found it hard to explain what I am doing 
> with just words.
> 
> 
> Thanks,
> 
> Eric
> 
> 
> <!--Start of Shipping type Section 
> -->
>    <TABLE  WIDTH=700 class="bord" BORDER=0 CELLPADDING=2 CELLSPACING=0 
> align="center">
>            <TR> 
> 
>                  <TD class="bord" align="center"><span 
> class="title">Shipping Method</span></TD>
>            </TR> 
> 
>            <TR> 
> 
>                  <TD> 
> 
>                          <!--second color 
> table-->
>                          <TABLE  WIDTH=700 class="main" BORDER=0 
> CELLPADDING=10 CELLSPACING=0 align="center">
>                                  <TR> 
> 
>                                    <TD class="main" 
> align="center">
>                                    <!--pieces 
> table-->
>                              <TABLE WIDTH=95% BORDER=0 CELLPADDING=0 
> CELLSPACING=0 align="center">
>                      <tr> 
> 
>                                    <td><IMG 
> SRC="https://www.host.com/htmltemp_consol/images/spacer.gif"; WIDTH=10 
> HEIGHT=5></TD>
>                                </tr> 
> 
>                      <tr>
>                        <td>
>                          <table align="center">
>                            <tr>
> 
> 
> 
>                  <label 
> for="ship4"> 
> 
>                  <TD width=15 align="right"><input type=radio id="ship4" 
> name="ship_option" value="4" Checked></TD>
>                  <TD width=65 class="boxfields" align="center" valign="top">
>                  <img src="images/shipping/ups_2D.gif" alt="LEM Domestic 
> "><br><b>$10.00</b></TD>
>                  </label>
> 
>                      </tr>
>                    </table>
>                  </td>
>                </tr> 
> 
>                          <tr> 
> 
>                                  <td><IMG 
> SRC="https://www.host.com/htmltemp_consol/images/spacer.gif"; WIDTH=10 
> HEIGHT=5></TD>
>                                </tr> 
> 
>                        </table> 
> 
>                        <!--end of pieces 
> table-->
>                </td> 
> 
>                </tr> 
> 
>                  </table> 
> 
>                  <!--end of second color 
> table-->
>                  </TD> 
> 
>            </TR> 
> 
>          </table> 
> 
>    <!--end of Shipping type Section-->
> 
> 
> 
> 
> 
> 
> 
> 
> -------------------------------------------------------
> 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. 
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Html-template-users mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/html-template-users
>


-------------------------------------------------------
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.
http://productguide.itmanagersjournal.com/
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to