On 01/03/11 22:32, Bill Ward wrote: > On Tue, Mar 1, 2011 at 2:26 PM, Mike Raynham <[email protected] > <mailto:[email protected]>> wrote: > > On 01/03/11 22:14, Bill Ward wrote: > > On Tue, Mar 1, 2011 at 2:09 PM, Mike Raynham > <[email protected] <mailto:[email protected]> > <mailto:[email protected] > <mailto:[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. > > > True, and it could get messy if you need to escape reserved > characters. You might find this answer useful: > > > http://mail.template-toolkit.org/pipermail/templates/2001-December/002253.html > > > Yeah, that's a good solution. Only thing is, you have to be careful not > to copy code from templates under an app that has that vmethod added > into one that doesn't. That's why I generally prefer to not customize > the engine.
Template::Plugin::String has a lower() method, but it's still not a simple one-liner: http://template-toolkit.org/docs/modules/Template/Plugin/String.html#method_lower It would be contained within the template though: [% USE String %] [% foo = String.new('Bar') %] [% 'foobar' IF foo.lower == 'bar' %] _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates
