[TYPO3-mvc] Use of an object as argument in a view helper in Fluid

Glenn W sonstiges at kusardi.de
Thu Nov 21 14:47:25 CET 2013


Hello,

I've created an own class which I want to use in Fluid. So I added the following code to the controller action.

$o = new \Vendor\Ext\Class();
$this->view->assign('object', $o);

In the template I can use the object as expected. For example the following does work (so the object is present and methods can be called):

<f:if condition="{object.methodReturningBoolean}">Foo</f:if>

Because I want to check for a condition by calling a method with a defined parameter, I created an own view helper:

namespace Vendor\Ext\ViewHelpers;
class IfViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\IfViewHelper {
public function render($object, $param) {
return parent::render(!$object->hasError($param));
}
}

and called it from the template:

<ext:if object="{object}" param="bar">Display if true</ext:if>

Should that work? At the moment I get the exception "Cannot cast object of type 'Vendor\Ext\Class' to string". It seems that my object is treated as string. I assumed that the variable is somewhat prepared, so I tried a 'object="{object -> f:format.raw()}"' which didn't work either. But a <f:debug>{object}</f:debug> right in front of the view helper is returning an object of type Vendor\Ext\Class.

TIA, best regards,
Glenn


More information about the TYPO3-project-typo3v4mvc mailing list