Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

iteration count in templates


3 Posts   2077 Views


Google Summer of Code Hacker, 39 Posts

7 July 2007 at 10:35am

i made a quick attempt at implementing this in ssviewer, but i was unsuccessful, so before i pour more time into this, im curious if anyone has some insight into the best way to do this



Google Summer of Code Hacker, 39 Posts

7 July 2007 at 11:18am

Edited: 07/07/2007 11:20am

ok well i got it working, but i am skeptical of the quality of my implementation

it goes as follows:
In SSViewer.php
around line 191:
'/\$Iteration/' => '<?= {dlr}key ?>',

this is added as the first replacement case, so it maps a call of $Iteration in a template to $key

also, the control foreach loops in SSViewer are changed from foreach($loop as $item) to foreach($loop as $key => $item) so that the $key is tracked, thus giving the iteration number

this does, of course raise the issue of reserving the $Iteration variable

this is confirmed as being functional in a few cases that meet my needs, but please give me your feedback, it could be a hack :)


Administrator, 685 Posts

8 July 2007 at 9:37pm

This does seem like something that would be better implemented as a method on ViewableData.

In fact, the skeleton of it is already there: $this->iteratorPos is a numeric value used to create boolean variables such as $Even, $Odd, $First, $Last. It's populated by a call to ViewableData::iteratorProperties() by the DataObjectSet object that contains each item.

That should give you enough to go on, let me know what you come up with ;-)