[PHPTAL] How do you print a grid with tal:repeat ?
Levi Stanley
levi at eneservices.com
Mon Feb 19 21:39:38 CET 2007
Hi Taylor Dondich:
Not sure if there is another way, but here is an example of what you are
asking for. However, if someone has a better way of doing, I would
really like to know.
Example php code:
<?php
include_once('PHPTAL.php');
$items = array('Mike', 'Juniper', 'Aarron', 'Karl', 'John',
'Michelle');
$template = new PHPTAL('test.xhtml');
$template->set('items', $items);
try {
print $template->execute();
} catch (Exception $e){
print "Error: ".$e->getMessage()."\n";
}
?>
Here is the test.xhtml file:
<html>
<head>
</head>
<body>
<table id='name'>
<tr tal:repeat="row php: range(0,(count(items)/2)-1)" >
<td tal:repeat="col php: range(0,1)">
<span tal:define="x php: row*2 + col"
tal:condition="exists: items/${x}" tal:replace="items/${x}" />
</td>
</tr>
</table>
</body>
</html>
I hope this helps.
Best regards,
Levi
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!
>
More information about the PHPTAL
mailing list