TYPO3 CMS  TYPO3_6-2
CaseViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
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. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
21 
31  public function render($value = NULL, $default = FALSE) {
32  $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
33  if (!$viewHelperVariableContainer->exists('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')) {
34  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('The case View helper can only be used within a switch View helper', 1368112037);
35  }
36  if (is_null($value) && $default === FALSE) {
37  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('The case View helper must have either value or default argument', 1382867521);
38  }
39  $switchExpression = $viewHelperVariableContainer->get('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression');
40 
41  // non-type-safe comparison by intention
42  if ($default === TRUE || $switchExpression == $value) {
43  $viewHelperVariableContainer->addOrUpdate('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'break', TRUE);
44  return $this->renderChildren();
45  }
46  return '';
47  }
48 }
render($value=NULL, $default=FALSE)