Alternating Row Colors with Zend PartialLoop

How to alternate table or list row colors in the partialLoop call of Zend.

The code snippets below should give you the idea. Every alternating TR tag will have a class of "a". Then, in the style sheet, just define a background color for TR tags with that class. You can alternate the class by using the partialCounter variable of the view, which contains the current index of the array.

index.phtml

Alternative

With the old Zend Framework, you needed to save the row state in the parent view, which is accessed through the PartialLoop helper. The code is the same as above, except the partialList.phtml is changed slightly.