Zum Inhalt springen

Eigener Viewhelper mit renderThenChild()

Erstellt am 31. Januar 2017 · 1 Antwort · letzte Antwort am 1. Februar 2017

Tags: TYPO3 7, Frage

mic187 ·

hallo habe ein problem mit einem viewhelper.

mein viewhelper sieht so aus.

use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
 * ViewHelper 
 */
class InarrayViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
 
 	/**
	 * @param mixed $favorit View helper condition
	 * @param mixed $video View helper condition
	  * @return bool|string
	 */
	public function render($favorit, $video) {
 
		$flag = FALSE;
		if($favorit != ""){
			foreach ($favorit as $value) {
		
				if(is_object($value)){
					if ($value->getRemove() == $video) {
						$flag = TRUE;
					}
				}else{
					if ($value == $video) {
						$flag = TRUE;
					}
				}
			}
		}
/*
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($flag);
die;
*/
		if ($flag) {
			return $this->renderThenChild();
		} else {
			 return $this->renderElseChild();
		}
	}
	
	    
 /**
	 * The compiled ViewHelper adds two new ViewHelper arguments: __thenClosure and __elseClosure.
	 * These contain closures which are be executed to render the then(), respectively else() case.
	 *
	 * @param string $argumentsVariableName
	 * @param string $renderChildrenClosureVariableName
	 * @param string $initializationPhpCode
	 * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode
	 * @param \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler
	 * @return string
	 * @internal
	 */
	public function compile(
		$argumentsVariableName,
		$renderChildrenClosureVariableName,
		&$initializationPhpCode,
		\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode,
		\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler
	) {
		parent::compile(
			$argumentsVariableName,
			$renderChildrenClosureVariableName,
			$initializationPhpCode,
			$syntaxTreeNode,
			$templateCompiler
		);
		return \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler::SHOULD_GENERATE_VIEWHELPER_INVOCATION;
	}
}

Jetzt bekomme ich immer diese meldung
Call to undefined method InarrayViewHelper::renderThenChild()

mic187 · · Beste Antwort

class InarrayViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper {

war die lösung.