Hello,
I have a question about the nature of truth (in TT2). I am finding that
empty arrays passed from my module always test true in my templates and
that I have to use [% IF myArray.size > 0 %] rather than [% IF myArray
%] to test whether to take action on array data. The following sub and
template snippet demonstrated the problem. Both empty_array and
empty_ref test true in my template conditionals.
Is this the intended behavior?
TIA,
David Martin
### PERL ###
sub test {
my $self = shift;
my @ary = ();
# if (@ary) { print "Array!" } else { print "Boo!" }
# Perl says Boo!
return $self->render_page(
'test.html',
{
empty_array => [ @ary ], # true
empty_ref => [], # true
no_array => '' # false
}
);
}
### TEMPLATE ###
<p>empty_array is [% IF empty_array %]true[% ELSE %]false[% END %]!</p>
<p>empty_ref is [% IF empty_ref %]true[% ELSE %]false[% END %]!</p>
<p>no_array is [% IF no_array %]true[% ELSE %]false[% END %]!</p>
### OUTPUT ###
empty_array is true!
empty_ref is true!
no_array is false!
All you have to do is decide
what to do with the time that
is given to you.
~ GTG
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates