On Tue, Mar 1, 2011 at 2:09 PM, Mike Raynham <[email protected]>wrote:

> On 01/03/11 20:48, Bill Ward wrote:
> > I know we can use a filter to convert to lower case, [% foo | lower %]
> > but that only works for output.  What I want is to do a case-insensitive
> > [% IF %] test, and normally in Perl I would just lc($foo) and compare
> > that to the desired value.  But how to do that in a template?
> >
> You could try a regex match.  The following outputs 'foobar':
>
> [% foo = 'Bar' %]
> [% 'foobar' IF foo.match('(?i)^bar$') %]
>
>
Yeah, that's a bit convoluted but should work.  I think the FILTER approach
is probably more efficient though.

The issue here is that my database values are all lowercase, but I wanted to
display a menu in mixed case, and have the currently selected value appear
in lowercase as well as the value attribute of the <option> tag be the
lowercase value.  Since this is an admin page it's not a huge deal and I'll
just display lowercase, but this seemed to me to be something that should be
easily doable without having to do strange hacks.  It'd be pretty easy to
add some new vmethods to a future version of the Template Toolkit if the
powers that be agreed with me....?
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to