1

I try to pass an array within my Viewhelper to the Fluidtemplate. It always shows the string "Array". If I try to use it as parameter in the f:for each viewhelper, I get an exception because it is a string and not an array. I used Typo3 6.2 before, now I have Typo3 7 and it stopped working.

public function render($uids) { // $uids='901,902,903'
    $uidArray = explode(',', $uids);

    $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
    $repository = $objectManager->get('XXX\\X\\Domain\\Repository\\FooRepository');
    $query = $repository->createQuery();
    $query->getQuerySettings()->setRespectStoragePage(FALSE);
    $query->matching(
        $query->in('uid', $uidArray)
    );
    return $query->execute()->toArray();
}

This is my Fluid template:

{namespace vh=My/Namespace/ViewHelpers}
<f:for each="{vh:GetArray(uids: '901,902,903')}">...</f:for>
andreas
  • 16,357
  • 12
  • 72
  • 76
ellei
  • 73
  • 1
  • 7

2 Answers2

3

You cannot return an array with your viewhelper, because viewhelper always return strings.

You can however introduce a new variable to the current render context and then use this variable inside your viewhelper.

public function render() {
  $returnArray = array('a' => 17, 'b' => 42);
  $this->templateVariableContainer->add('returnArray', $returnArray);
  $output = $this->renderChildren();
  $this->templateVariableContainer->remove('returnArray');
  return $output;
}

Inside your template you can then run a for loop over {returnArray}.

pgampe
  • 4,531
  • 1
  • 20
  • 31
  • this works, thx! just dont understand why they changed it this way. It was possible to return an array directly to fluid – ellei May 08 '16 at 13:05
0

Try a combination of f:for and f:cycle in your Fluid template. See the f:cycle examples in the Fluid ViewHelper Reference.

Andrew
  • 585
  • 4
  • 17
  • This would not work, because i cannot use a viewhelper which expects an array as parameter. The return value of my viewhelper is an string not an array. – ellei May 07 '16 at 14:31