TYPO3 (TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper) 中有一个新的 AbstractViewHelper,我尝试用它为我的项目实现一个非常简单的 InArrayViewHelper。
问题是,如果您想根据https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/8-Fluid/8-developing-a-render()访问then或子标签,您应该使用custom-viewhelper.html#renderstatic-methodelse
所以我做了类似的事情
<?php
namespace Vendor\Project\ViewHelpers;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
class InArrayViewHelper extends AbstractViewHelper {
//use CompileWithRenderStatic;
public function initializeArguments() {
$this->registerArgument('haystack', 'mixed', 'View helper haystack ', TRUE);
$this->registerArgument('needle', 'string', 'View helper needle', TRUE);
}
public function render() {
$needle = $this->arguments['needle'];
$haystack = $this->arguments['haystack'];
if(!is_array($haystack)) {
return $this->renderElseChild();
}
if(in_array($needle, $haystack)) {
return $this->renderThenChild();
} else {
return $this->renderElseChild();
}
}
}
好吧,但他们搬走了renderThenChild并renderElseChild在那里。这样做的正确方法是什么。我可以不用 \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper 吗?
桃花长相依