2 namespace TYPO3\CMS\Fluid\ViewHelpers
;
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
11 * The TYPO3 project - inspiring people to share! *
15 * Case view helper that is only usable within the SwitchViewHelper.
16 * @see \TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper
20 class CaseViewHelper
extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
24 * @return string the contents of this view helper if $value equals the expression of the surrounding switch view helper, otherwise an empty string
25 * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
28 public function render($value) {
29 $viewHelperVariableContainer = $this->renderingContext
->getViewHelperVariableContainer();
30 if (!$viewHelperVariableContainer->exists('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')) {
31 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\
Exception('The case View helper can only be used within a switch View helper', 1368112037);
33 $switchExpression = $viewHelperVariableContainer->get('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression');
35 // non-type-safe comparison by intention
36 if ($switchExpression == $value) {
37 $viewHelperVariableContainer->addOrUpdate('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'break', TRUE);
38 return $this->renderChildren();