Problem: I wrote a conditional VH (extending AbstractConditionViewHelper
) and it works as usually, anyway I realized that in non-cached version it is evaluated only once. Initialy I thought that's my bug, but checked common <f:if>
and the problem is identical :S
In general when I visit my page for the first time, condition is evaluated and valid result is given, but when I'll refresh the page VH isn't called anymore (checked by setting breakpoint inside the VH) and VH is always treated as FALSE. Only any change in view's code will cause that VH will be evaluated once, and again next refresh(es) won't call VH anymore.
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();
}
}
Usage:
{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>
For the first hit I have TRUE
but later only FALSE
.
Any suggestions? Did I missed some important change in ViewHelpers API since 7.x- ?
Of course if extension is cached it will be not visible, as the first hit will be saved in cache with proper VH return.