Zend Framework View Helper for Smarty Cycle
by Gabi SolomonAs i stated in a recent post i am now starting to learn Zend Framework. And with all new things that you learn, you try to find the old ways ( at least i do
).
So today i was trying to find a method of creating a zebra table. The old way i used to this back when i was using smarty is by using the cycle custom function. Basically it will just alternate through a set of values to create the effect.
-
{section name=rows loop=$data}
-
<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
-
<td>{$data[rows]}</td>
-
</tr>
-
{/section}
Then when i moved on and stop using smarty, i wrote a similar function for my template engine.
So now i am looking for a similar solution on Zend Framework. Luckily for me some bright fellows have already thought of me
.
In the zend wiki there is a Zend_View_Helper_Cycle Component Proposal that does exacly what i was wishing for
.
Heres an example of how you can use it:
-
<?php foreach ($this->books as $book):?>
-
<tr style="background-color:<?=$cycle->next()?>">
-
<td><?=$this->escape($book['author']) ?></td>
-
</tr>
-
<?php endforeach;?>
The proposal has been approved for development in standard/incubator.
You can download it from here.
Cheers.
Related Posts
-
Sean
-
Sean
-
Gabi Solomon
-
Ralph Schindler
-
Gabi Solomon
-
Ralph Schindler
-
Ralph Schindler
-
Jani Hartikainen

