If for some reason grep isn't good enough, you can easily add your own
virtual method to arrays:
use Template::Stash;
$Template::Stash::LIST_OPS->{contains} = sub {
my ($haystack, $needle) = @_;
foreach my $el (@$kaystack) {
return 1
if $el eq $needle;
}
return undef;
};
Then you'd say
[% IF c.req.param.contains('x') %]
(if you want something to work both with arrays and hashes, then name
your method "exists" rather than "contains" ;-)).
-M.
On Sun, 2007-10-07 at 21:40 +0100, Paul Makepeace wrote:
> I'm wondering if there's been any discussion on augmenting TT with a
> pythonic (and many others) IN keyword. Allowing something awesomely
> compact and readable like,
>
> <input type="checkbox" name="[% name %]" value="[% val %]"
> [% IF val IN c.req.param(name); 'checked="checked"'; END %] />
>
> I'm at a loss how to achieve that without building up a hash. Any tips?
>
> P
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://lists.template-toolkit.org/mailman/listinfo/templates
>
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates