I've put together a very simple chunk iterator [1] which works with arrays, traversables and iterators. There is also an example tales modifier.

Perhaps it could even be added to the standard PHPTAL code base?

[1] http://gist.github.com/266759


On 12/31/09 11:02 AM, Kornel Lesiński wrote:
On 31-12-2009 at 04:44:34 romtek <rom...@gmail.com> wrote:

Thank you very much  for this sample! It's much more elegant, easier to
understand and maintain than what I've come up with. Things like this had better be published in a special section of documentation. And I hope that array_chunk() doesn't copy data needlessly. This method does introduce more

Kornel, what would you do if data were a collection but not an array
(besides using something like what was suggested by Rasmus Schultz at

If it's small enough to fit in memory, then probably conversion to array with iterator_to_array() will be fastest.

Otherwise you could write something like IteratorIterator http://www.php.net/IteratorIterator that ignores reset() and pretends it ends every n elements.

PHPTAL mailing list

Reply via email to