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>
4
  • what do you get if you pass your viewhelper to the debug viewhelper? Commented May 7, 2016 at 22:43
  • Something like that: 'Array' String(5) Commented May 8, 2016 at 9:46
  • That means your array is already casted to a string before being returned by the viewhelper. Commented May 8, 2016 at 11:32
  • exactly, and i dont understand why - thats my problem Commented May 8, 2016 at 13:04

2 Answers 2

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}.

Sign up to request clarification or add additional context in comments.

1 Comment

this works, thx! just dont understand why they changed it this way. It was possible to return an array directly to fluid
0

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.