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
thanks
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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
thanks
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 :)
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 ;-)