[Templates] IN keyword?
Cees Hek
ceeshek at gmail.com
Tue Nov 20 00:13:53 GMT 2007
On Oct 8, 2007 7:57 AM, Jonathan Rockway <jon at jrock.us> wrote:
> 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?
> How about:
>
> use Perl6::Junction;
> my $possible_values = any(@possible_values)
> ---
> [% IF value == possible_values %] value is one of @possible_values [%
> END %]
What I am eagerly waiting for is the new ~~ smart match operator in
perl 5.10 [1]. That should be easy enough to add into the Template
parser as a valid operator which would then allow pretty much exactly
what Paul is after:
<input type="checkbox" name="[% name %]" value="[% val %]"
[% IF val ~~ c.req.param(name); 'checked="checked"'; END %] />
Which really just replaces 'IN' with '~~' in Paul's original example.
As for the actual example here, I abandoned manually checking
checkboxes like this long ago. Look at the FillInForm plugin, or use
a widget library that auto-generates your checkboxes (I prefer
Rose::HTML::Object but there is also HTML::Widget::Factory and good
old CGI.pm among others)
[1] http://search.cpan.org/~rgarcia/perl-5.9.5/pod/perlsyn.pod#Smart_matching_in_detail
More information about the templates
mailing list