On Thu, 21 Jul 2005, Will wrote:
> I have in my script:
>
> my @volumes = S::Volumes->retrieve_all;
> my $vars = {'volumes' => @volumes};
As Dave pointed out, you need to pass a reference to the array but if yo
have a large dataset, it may be more efficient to use the
Class::DBI::Iterator
# in scalar context returns an iterator
my $volumes = S::Volumes->retrieve_all;
my $vars = { volumes => $volumes };
> In my template:
> [% FOREACH item IN volumes %]
> * [% item %]
> [% END %]
[% WHILE (item = volumes.next) %]
* [% item %]
[% END %]
> Any insight would be greatly appreciated. Also, how might I mix the
> results of a retrieve_all and a simple retrieve($id) into the same
> template (or the same $var to pass to process() I guess).
You could use Template::Plugin::Class[1] to give you direct access to the
Class::DBI objects
[% USE volumes = Class('S::Volumes') %]
[% FOREACH item IN volumes.retrieve_all %]
* [% item %]
[% END %]
In fact the docs for the module describe doing exactly that :-)
HTH,
Simon.
[1] http://search.cpan.org/~rclamp/Template-Plugin-Class-0.12/
--
"Is there any tea on this spaceship ?"
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates