2009/12/30 Kornel Lesiński <kor...@aardvarkmedia.co.uk>

> On 29-12-2009 at 22:06:13 romtek <rom...@gmail.com> wrote:
>
>  I was looking for a more elegant way to generate grids using PHPTAL that
>> what I've been using and stumbled upon this post:
>> http://lists.motion-twin.com/pipermail/phptal/2007-February/000730.html.
>> In
>> it, Aaron McClimont has proposed adding a "while" loop (and also
>> dowhile)construct to PHPTAL. I think it's very valuable as it allows for
>> much more elegant code in certain situations. Has this been added to the
>> library? If not, could it be?
>>
>
> Are there any other uses for while?
>
> Variable number of columns can be done more elegantly than by _copying &
> pasting_ code, and it can even vary at run time:
>
> <tr tal:repeat="row php:array_chunk(data, number_of_columns)">
>  <td tal:repeat="col row" tal:content="col" />
> </tr>
>

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
overhead.

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
http://php.net/manual/en/function.array-chunk.php)?
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to