eXile has asked for the wisdom of the Perl Monks concerning the following question:
I want to be able to use both Class::DBI::Iterator and lists in TT, but I can only get lists to work:sub auxdata { my $self = shift; if (wantarray) { # returns a list-ref return [ $self->auxclass->retrieve_all() ]; } else { # returns an interator return $self->auxclass->retrieve_all(); } }
This doesn't work:[% FOREACH aux = object.auxdata %] <option value="[% aux.id %]">[% aux.name %]</option> [% END %]
If I add print statements to my auxdata method I see it is called in list-context every time. What am I doing wrong? What is the correct way of getting this to work?[% WHILE ax = a.auxdata.next %] ID [% ax.id %] [% END %]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Template Toolkit scalar vs list context
by Errto (Vicar) on Dec 11, 2004 at 03:47 UTC |