Forgot -- Re: [PHPTAL] How do you print a grid with tal:repeat ?
Aaron McClimont
mcclimont at internode.on.net
Tue Feb 20 02:36:33 CET 2007
A while ago i posted a patch to PHPTAL to enable the use of tal:while,
and later added also tal:dowhile but didn't post the patch.
http://lists.motion-twin.com/pipermail/phptal/2005-November/000501.html
Here is one use of this to display a grid of 3 columns wide and as many
rows as required.
<table>
<tal:block tal:while="php: next(items)">
<tr>
<td tal:define="item php:current(items)">
<div tal:condition="item" tal:content="item">Default Text</div>
</td>
<td tal:define="item php:next(items)">
<div tal:condition="item" tal:content="item">Default Text</div>
</td>
<td tal:define="item php:next(items)">
<div tal:condition="item" tal:content="item">Default Text</div>
</td>
</tr>
</table>
Adding / removing columns can be done just by duplicating the cell code,
or the code could be rearranged slightly to allow a dynamic amount of
columns.
The use of a macro could help to define and contain the logic of what
the contents of each cell looks like if there is something to display,
or generic content if there is not.
Aaron.
Taylor Dondich wrote:
> That is pretty crazy, as it requires the php modifier. Is this truly
> the most elegant way of doing this with PHPTAL? If so, I'll take it.
> Just wanted to see if any others had any ideas?
>
> Taylor
>
> Levi Stanley wrote:
>> Forgot to think of the case of not even array, so fixed it in this
>> version Take a look at the xhtml:
>>
>> <html>
>> <head>
>> </head>
>> <body>
>> <table id='name'>
>> <tr tal:repeat="row php: range(0,(ceil(count(items)/2))-1)" >
>> <td tal:repeat="col php: range(0,1)">
>> <span tal:define="global x php: row*2 + col"
>> tal:condition="exists: items/${x}" tal:replace="items/${x}" />
>> <span tal:condition="not: exists: items/${x}"
>> > </span>
>> </td>
>> </tr>
>> </table>
>> </body>
>> </html>
>>
>>
>> I added the span with the   in it. And I changed the row to use
>> the ceiling fuction so you won't be missing a row.
>> Taylor Dondich wrote:
>>> Suppose I have 13 items in my collection, and I want to print a table
>>> with 2 columns and as many rows as needed for my collection. How do
>>> I do that? And if the last row only has one item, how do I know to
>>> print the empty td element?
>>>
>>> Anyone have any ideas or best practices for this?
>>>
>>> Taylor
>>>
>>> _______________________________________________
>>> PHPTAL mailing list
>>> PHPTAL at lists.motion-twin.com
>>> http://lists.motion-twin.com/mailman/listinfo/phptal
>>>
>>> !DSPAM:1,45d9d508248767836945438!
>>>
>>
>
>
> _______________________________________________
> PHPTAL mailing list
> PHPTAL at lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>
More information about the PHPTAL
mailing list