velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject Re : More control in foreach
Date Mon, 12 Feb 2001 19:31:58 GMT
> From: []

> One of the things I want to do is pageination - every site I've built
> needs this. One way to implement is to cache a big array
> server side and
> just display relavent parts from it. It would be nice if the #foreach
> macro was more like a regular for, where you can define the
> start and end
> index.

When you want to iterate over integers, why not use something like :

#foreach( $i in [$start..$end])

where $start and $end are the starting and ending values.

That's like a regular for, isn't it?

Otherwise, you can simply set up your array in your servlet, or write a
little helper routine for yourself to return something with the correct
shape, a la :

#foreach( $i in $helper.getArray( $whatever ) )

> And really nice would be a #Break to get out of the #foreach.
> I suspect that we can create our own macros? To do such things?

You can write VTL 'macros' via the Velocimacro features (see the docs) or
write your own plug-in directives.  Try the Velocimacros first...  then try
them second... after that, reconsider what you are trying to do... then try
Velocimacros again.   Then think about using the Velocity utility class to
both render dynamic templates or call Velocimacros from your Java code.

Give Velocimacros one last try...

 THEN think about writing a directive :)


p.s. praying this is not HTML.

View raw message