TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
SwitchViewHelper Class Reference
Inheritance diagram for SwitchViewHelper:

Public Member Functions

 compile ($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
 

Protected Member Functions

 isDefaultCaseNode (NodeInterface $node)
 
 isCaseNode (NodeInterface $node)
 

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:defaultCase>Mrs. or Mr.</f:defaultCase> </f:switch> <output> Mr. / Mrs. (depending on the value of {person.gender}) or if no value evaluates to TRUE, defaultCase </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 46 of file SwitchViewHelper.php.

Member Function Documentation

compile (   $argumentsName,
  $closureName,
$initializationPhpCode,
ViewHelperNode  $node,
TemplateCompiler  $compiler 
)
Parameters
string$argumentsName
string$closureName
string$initializationPhpCode
ViewHelperNode$node
TemplateCompiler$compiler

Definition at line 87 of file SwitchViewHelper.php.

isCaseNode ( NodeInterface  $node)
protected
Parameters
NodeInterface$node
Returns
bool

Definition at line 71 of file SwitchViewHelper.php.

isDefaultCaseNode ( NodeInterface  $node)
protected
Parameters
NodeInterface$node
Returns
bool

Definition at line 52 of file SwitchViewHelper.php.