TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper Class Reference
Inheritance diagram for TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper:
TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface

Public Member Functions

 setChildNodes (array $childNodes)
 
 render ($expression)
 
- Public Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 setArguments (array $arguments)
 
 setRenderingContext (\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 
 injectObjectManager (\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
 
 injectReflectionService (\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
 
 isEscapingInterceptorEnabled ()
 
 setViewHelperNode (\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode $node)
 
 setRenderChildrenClosure (\Closure $renderChildrenClosure)
 
 initializeArgumentsAndRender ()
 
 initialize ()
 
 renderChildren ()
 
 prepareArguments ()
 
 validateArguments ()
 
 initializeArguments ()
 
 compile ($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler)
 
 resetState ()
 
- Public Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface
 compile ($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler)
 

Static Public Member Functions

static renderStatic (array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 
- Static Public Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
static renderStatic (array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 
- Static Public Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface
static renderStatic (array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 

Protected Attributes

 $backupSwitchExpression = null
 
 $backupBreakState = false
 
- Protected Attributes inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 $arguments
 
 $templateVariableContainer
 
 $controllerContext
 
 $renderingContext
 
 $renderChildrenClosure = null
 
 $viewHelperVariableContainer
 
 $objectManager
 
 $escapingInterceptorEnabled = true
 

Private Attributes

 $childNodes = []
 

Additional Inherited Members

- Protected Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 registerArgument ($name, $type, $description, $required=false, $defaultValue=null)
 
 overrideArgument ($name, $type, $description, $required=false, $defaultValue=null)
 
 callRenderMethod ()
 
 getLogger ()
 
 buildRenderChildrenClosure ()
 
 hasArgument ($argumentName)
 

Detailed Description

Switch view helper which can be used to render content depending on a value or expression. Implements what a basic switch()-PHP-method does.

= Examples =

<f:switch expression="{person.gender}"> <f:case value="male">Mr.</f:case> <f:case value="female">Mrs.</f:case> <f:case default="TRUE">Mrs. or Mr.</f:case> </f:switch> <output> Mr. / Mrs. (depending on the value of {person.gender}) or if no value evaluates to TRUE, default case </output>

Note: Using this view helper can be a sign of weak architecture. If you end up using it extensively you might want to consider restructuring your controllers/actions and/or use partials and sections. E.g. the above example could be achieved with <f:render partial="title.{person.gender}" /> and the partials "title.male.html", "title.female.html", ... Depending on the scenario this can be easier to extend and possibly contains less duplication.

Definition at line 44 of file SwitchViewHelper.php.

Member Function Documentation

◆ render()

TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::render (   $expression)
Parameters
mixed$expression
Returns
string the rendered string

Definition at line 78 of file SwitchViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\buildRenderChildrenClosure().

◆ renderStatic()

static TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::renderStatic ( array  $arguments,
\Closure  $renderChildrenClosure,
RenderingContextInterface  $renderingContext 
)
static

Default implementation for CompilableInterface. See CompilableInterface for a detailed description of this method.

Parameters
array$arguments
\Closure$renderChildrenClosure
RenderingContextInterface$renderingContext
Returns
mixed
See also

Definition at line 99 of file SwitchViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\$renderChildrenClosure, TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\$viewHelperVariableContainer, and TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface\getViewHelperVariableContainer().

◆ setChildNodes()

TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::setChildNodes ( array  $childNodes)

Setter for ChildNodes - as defined in ChildNodeAccessInterface

Parameters
array$childNodesChild nodes of this syntax tree node
Returns
void

Implements TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface.

Definition at line 68 of file SwitchViewHelper.php.

References TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper\$childNodes.

Member Data Documentation

◆ $backupBreakState

TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::$backupBreakState = false
protected

Definition at line 60 of file SwitchViewHelper.php.

◆ $backupSwitchExpression

TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::$backupSwitchExpression = null
protected

Definition at line 55 of file SwitchViewHelper.php.

◆ $childNodes

TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::$childNodes = []
private