On Sun, 30 Dec 2001, Alex Kirk wrote:

> First off, in reading the documentation, it appeared to me that I could use
> an array of references to hashes to fill in a TMPL_LOOP. I'd simply create
> my array, then call $template->param(LOOP_NAME => \@array).

Correct.

> However, this is not working properly for me; I'm wondering if it's
> because of how I'm constructing my array.

Can you describe what you mean by "not working properly"?

> Basically, I'm using DBI's fetchrow_hashref() method to return a reference
> to a hash, and then plunking that into an array. Thus, I can call
> $array[x]->{keyname} and get a value, no problem. Would I be able to
> properly use this with TMPL_LOOP, or do I need an array of hashes, not
> references to hashes?

An array of references to hashes is perfect, but you should read the docs
for DBI::fetchrow_hashref.  My memory is that it will return a reference
to the same hash everytime.  I think you'll need to make a private copy of
the hash or you'll end up with an array containing a list of references to
the last row in your dataset!

> Alternately, I've thought this problem could be due to me not using all of
> the keys in the hash as TMPL_VARs. Would this cause a problem?

That will cause HTML::Template to die() if die_on_bad_params is set to 1.
This is the default, so if you haven't set it to 0 then you'll definitely
have a problem.

> Second, I have several TMPL_LOOPs which are named "Q1", "Q2", etc., each of
> which contain the same TMPL_NAME variables. I'd like to be able to just loop
> through them and perform param()s on them; I figured I could simply build a
> string with the name of the TMPL_LOOP, and then pass it to param(), like so:
>
> for ($x=0; $x<5; $x++)
>   {
>   $base = "Q";
>   $name = $base.$x;
>   $template->param($name, \@array);
>   }

I can't see anything wrong with the code here, but I don't have enough
information to diagnose your problem.  One question - why would you define
multiple loops with different names and the same data?  You can re-use a
loop in a template as many times as you like.

So, in summary, you're going to have to provide more information about
exactly what you're doing and what's not working as you expect.  This
doesn't mean you should post your whole 1000 line CGI though - just put
together some small working examples that demonstrate your problem.  Also,
you might check that you're using the most recent version of
HTML::Template - 2.4.

-sam



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to