Re: [Templates] Foreach LOOP to create HTML

[prev] [thread] [next] [Date index for 2004/07/20]

From: Dave Cross
Subject: Re: [Templates] Foreach LOOP to create HTML
Date: 22:26 on 20 Jul 2004
On Tue, Jul 20, 2004 at 02:56:03PM -0700, Roderick A. Anderson wrote:
> I'm starting to create a some code that begs to be handled by TT (or 
> perl).  I can do it in the CGI script but I'd like ot try out this new 
> tool -- TT2.
> 
> Here's what I'm not liking using TT2.
> 
> 	<input type="radio" name="keepdays" value="3"  [% IF keepdays = 3 %]
> 		checked="checked" [% END %]/>3
> 	<input type="radio" name="keepdays" value="7"  [% IF keepdays = 7 %]
> 		checked="checked" [% END %]/>7
> 	<input type="radio" name="keepdays" value="14" [% IF keepdays = 14 %]
>         	checked="checked" [% END %]/>14
> 	<input type="radio" name="keepdays" value="30" [% IF keepdays = 30 %]
>         	checked="checked" [% END %]/>30
> 
> Seems to me there should be some ultra-slick TT2 method to do this but it
> escapes me -- even with the Badger book at hand.  Is there some already
> defined method to do this?

Something like this perhaps:

  [% days = [ 3, 7, 14, 30 ] %]
  [% FOREACH day IN days -%]
  <input type="radio" name="keepdays" value="[% day %]"
    [%- IF keepday == day %] checked="checked"[% END %]/>[% day %]
  [% END %]

hth,

Dave...

        -- 
          We are far too young and clever

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] Foreach LOOP to create HTML
Roderick A. Anderson 21:56 on 20 Jul 2004

Re: [Templates] Foreach LOOP to create HTML
Gavin Estey 22:23 on 20 Jul 2004

Re: [Templates] Foreach LOOP to create HTML
Dave Cross 22:26 on 20 Jul 2004

Re: [Templates] Foreach LOOP to create HTML
Roderick A. Anderson 22:44 on 20 Jul 2004

Generated at 08:55 on 15 Mar 2005 by mariachi v0.52