问题:我写了一个有条件的 VH(扩展AbstractConditionViewHelper
)并且它像往常一样工作,无论如何我意识到在非缓存版本中它只被评估一次。最初我认为这是我的错误,但检查常见<f:if>
问题是相同的:S
一般来说,当我第一次访问我的页面时,会评估条件并给出有效结果,但是当我刷新页面时,不再调用 VH(通过在 VH 内设置断点进行检查)并且 VH 始终被视为错误的。只有视图代码中的任何更改都会导致 VH 将被评估一次,并且下一次刷新将不再调用 VH。
Typo3conf/ext/toolbox/Classes/ViewHelpers/IsFieldRequiredViewHelper.php:
<?php
namespace Vendor\Toolbox\ViewHelpers;
class IsFieldRequiredViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper {
/**
* @param string $fieldName Current field name
* @param string $requiredFields List of required names separated by commas
*
* @return string the rendered string
*/
public function render($fieldName, $requiredFields) {
$requiredArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $requiredFields, true);
return (in_array($fieldName, $requiredArray))
? $this->renderThenChild()
: $this->renderElseChild();
}
}
用法:
{namespace toolbox=Vendor\Toolbox\ViewHelpers}
<toolbox:isFieldRequired fieldName="foo" requiredFields="foo, bar, baz">
<f:then>TRUE</f:then>
<f:else>FALSE</f:else>
</toolbox:isFieldRequired>
对于第一个打击我有TRUE
但后来只有FALSE
。
有什么建议么?自 7.x- 以来,我是否错过了 ViewHelpers API 的一些重要变化?
当然,如果扩展被缓存,它将不可见,因为第一个命中将保存在缓存中并返回适当的 VH。