[Templates] "in array" function?
Josh Rosenbaum
josh at infogears.com
Wed Mar 5 20:34:58 GMT 2008
Chris Petersen wrote:
> I realize that it's somewhat un-perl, but is there a way to do "in"
> within TT? It would be nice to keep things clean when I have large
> lists of things I'm comparing a single variable to in an if-statement.
>
> [% IF var == 'foo' || var == 'bar' %]
>
> I've tried to use something like:
>
> [% IF [ 'foo', 'bar' ].grep(var) %]
>
> But it obviously fails.
>
> I realize that I can write my own vmethod for this, but it would be
> nice if something like this was already built in, so I could just:
>
> [% IF var IN ['foo','bar'] %]
>
> or
>
> [% IF var ! IN ['foo','bar'] %]
There's always var.match('^(foo|bar)$')
-- Josh
More information about the templates
mailing list