[TYPO3-mvc] Viewhelper looping child objects stops after one child object shown

Søren Andersen hacksaw at zpeed.dk
Sun Mar 24 14:58:33 CET 2013


Henjo,

I'm no expert, so it's just a wild guess.

Could it be that you need to do a ->rewind() on the object?

Instead of writing your own viewhelper, maybe you could go with the VHS
extension and use v:var.set and v:math.sum together to do the same job as
the viewhelper you are writing.

It would be something like this (assuming vhs is set to namespace v):
Place this before your loop to set the total value to 0: 
<v:var.set name="total" value="0" />
Inside your loop, do this:
<v:var.set name="total" value="{v:math.sum(a: '{total}', b:
'{object.number}')}" />

Now you can acces the value as {total}

Sincerely,
Søren Andersen

-----Oprindelig meddelelse-----
Fra: typo3-project-typo3v4mvc-bounces at lists.typo3.org
[mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] På vegne af Henjo
Hoeksma | Stylence
Sendt: 23. marts 2013 23:45
Til: TYPO3 v4 MVC project
Emne: [TYPO3-mvc] Viewhelper looping child objects stops after one child
object shown

Hi list,

I need a ViewHelper that calculates the percentage of a child object.

The child object contains a property called 'number' and I need to show the
percentage based upon the other child objects of the parent object.

I thought this would be easy: assign all the child objects to my viewhelper
and to some calculation there. It works, except for one thing: Only the
first child object is being returned when I start looping the others in my
VH.

Basically what I am doing is:

public function render($objects, $currentObject) {

$total = 0;
foreach ($objects as $object) {

$total = $total + $object->getNumber();

}
return $total;

}

What am I missing?

It is a 4.5 installation (extbase 1.3.3)

Kind regards,

Henjo

Problems are small because we learned how to deal with them.
Problems are big because we need to learn how to deal with them.
_______________________________________________
TYPO3-project-typo3v4mvc mailing list
TYPO3-project-typo3v4mvc at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc



More information about the TYPO3-project-typo3v4mvc mailing list