[Templates] reiteration question, by increments of something
other than 1
Josh Rosenbaum
josh@infogears.com
Wed, 26 Jul 2006 17:23:25 -0600
Me wrote:
> I need to do a FOREACH and increment by a number
> other than one.
>
> for example. I might have this..
>
> FOREACH y = [0..40]
>
> --> but I want to increment by 3
>
> so, it would print..
>
> 1, 3, 6, 9 etc.. up to 40 (of course, 3 doesn't go
> into 40 evently, so that last number to effectively
> take a 3).
>
> I don't want to do MOD. I want a more elequent
> solution if there is one.
>
> is there
Why not just use while?
[% y = 1 %]
[% WHILE y < 40 %]
do stuff here.
[% y = y + 3 %]
[% END %]
If you're absolutely determined to use foreach, I suppose you could create a routine that creates the list to use in the foreach.
ie:
[% FOREACH y IN get_incremented_list(1,40,3) %]
[% END %]
-- Josh