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

Florian Rival contact at oktopuce.fr
Thu Nov 21 15:56:02 CET 2013


Hi Glenn,

Did you use the DocComment (@param, @return, ...) in order to tell 
extbase the type of parameter you give to the ViewHelper ?

Like this :

   /**
   * @param \Vendor\Ext\Class $object
   * @param string $param
   * @return boolean
   */
public function render($object, $param) {

Regards,
Florian RIVAL
www.oktopuce.fr <http://www.oktopuce.fr/>

P*Please consider the environment before printing this email*

Le 21/11/2013 14:47, Glenn W a écrit :
> 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
> _______________________________________________
> 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