[Templates] Overriding the default iterator

[prev] [thread] [next] [Date index for 2004/09/03]

From: Buddy Burden
Subject: [Templates] Overriding the default iterator
Date: 01:43 on 03 Sep 2004
Guys,

Okay, so I find myself writing quite a lot of this:

[% FOREACH thing = buncha.things %]
	[% IF loop.count % 2 == 1 %]
		do the odd rows
	[% ELSE %]
		do the even rows
	[% END %]
[% END %]

which of course doesn't bother _me_ one whit, but it makes absolutely no 
sense to Jen, my non-programming template designer.  So I'm thinking 
that something like:

[% FOREACH thing = buncha.things %]
	[% IF loop.odd %]
		do the odd rows
	[% ELSE %]
		do the even rows
	[% END %]
[% END %]

would be very cool for her.  And it seems like it'd be trivial to implement.

Now, in the badger book, in the section on Template::Iterator, I can see 
how to create a class to do what I want.  Seems pretty basic.  What I'm 
wondering is is there any (reasonably simple) way to install this 
functionality so that I can get it for every loop?  I'd rather not have 
to replace all my arrayrefs with functions that return a special 
iterator; I think that'd negate the convenience to Jen with the 
inconvenience to me.  So I _think_ what I want to do is override the 
default iterator.  But I don't see how to do that.  (Or maybe I'm on the 
wrong track altogether.)

Any thoughts?


		-- Buddy

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

[Templates] Overriding the default iterator
Buddy Burden 01:43 on 03 Sep 2004

Re: [Templates] Overriding the default iterator
Adam Kennedy 05:31 on 03 Sep 2004

Re: [Templates] Overriding the default iterator
Andy Wardley 06:53 on 03 Sep 2004

Re: [Templates] Overriding the default iterator
Buddy Burden 16:36 on 03 Sep 2004

RE: [Templates] Overriding the default iterator
Thomas, Mark - BLS CTR 17:06 on 03 Sep 2004

Re: [Templates] Overriding the default iterator
Buddy Burden 17:38 on 03 Sep 2004

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