Re: [Templates] Array of hashes or hash refs
[prev]
[thread]
[next]
[Date index for 2004/09/24]
Roderick A. Anderson asks:
> [...]
> Currently I'm passing a hashref to the TT process
>
> $sut->process($filename, \%CSI); (No not Crime Scene
> Investigation :-)
>
> but now need to pass in a bunch of hashes(/refs) that will get displayed
> in a table. So %CSI would have ToDay => 'Sep 23, 2004'; PageTitle => 'Not
> doing so well', etc. I now need to pass in multiple hashes like
> this.
>
> { LastName => Smith, FirstName => John, ID => BR549 }
Note that you may omit quotes on hash keys, but not on values.
If you use strict. Which is what you should do anyway ;-)
> What kind of structure do I need to construct and pass in to TT? Heck ..
> can I pass in multiple hashes or even arrays?
Just build a hash containing references to all your data structures:
%CSI = (ToDay => 'Sep 23, 2004'; PageTitle => 'Not doing so well');
@array = ([ LastName => 'Smith', FirstName => 'John', ID => 'BR549' ]
,[ LastName => 'Anderson', FirstName => 'Rod', ID => 'BR007' ]
);
$sut->process($filename
,{'CSI' => \%CSI
,'array' => \@array
}
);
...and in your template you can have things like:
At [% CSI.ToDay %] [% array.0.FirstName %] [% array.0.LastName %] was
[% CSI.PageTitle %].
--
HTH,
haj
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
 |
Re: [Templates] Array of hashes or hash refs
Harald Joerg 09:54 on 24 Sep 2004
|