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
Ok, I'm assuming c.req.param(name) is returning a string with \0's in it. If
it's a list then a simple grep would work.
Not pretty and not very efficient, but this might work:
[% IF c.req.param(name).split('\0').grep("^$val\$").size() %]
or maybe something like:
[% IF c.req.param(name).match("(^|\0)$val(\0|\$)") %]
Note that the formatting or regular expressions could be off on those. I just
threw them out as an idea of what you might do so they may need refinement.
You might just want to create your own vmethod or routine to do this, though.
For example something like api.is_checked(name, value) or maybe
c.req.param(name).is_checked(value).
-- Josh
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates