Feature #33817

SwitchViewHelper

Added by Adrian Föder over 3 years ago. Updated about 2 years ago.

Status:Resolved Start date:2012-02-09
Priority:Could have Due date:
Assigned To:Bastian Waidelich % Done:

100%

Category:ViewHelpers
Target version:-
Has patch:No

Description

Fluid should provide a Switch VH that behaves like the well-known switch-case structure.

Syntax suggestion:

<f:switch comparand="{foo.bar}">
  <f:switch.case comparand="valuecase1">
    <span>Output in this case.</span>
  </f:switch.case>

  <f:switch.case comparand="nothervaluecase">
    <a>Output in another case.</a>
  </f:switch.case>

  <f:switch.case comparand="third">
    <a>Output in another case.</a>
  </f:switch.case>

  <f:switch.default>
    Default value if nothing else matches.
  </f:switch.default>
</f:switch>

There's an already present implementation here: http://fedext.net/fed-viewhelpers/loops-conditions/switch/ but tbh I at least don't agree with the "default" implementation because it could collide with the value being "default" as string:

<fed:switch value="{switchValue}">
  <fed:case case="1">
      <p>Case was 1</p>
  </fed:case>
  <fed:case case="default">
    <p>Case was default</p>
  </fed:case>
</fed:switch>

SwitchViewHelper.php Magnifier (2.7 kB) Bastian Waidelich, 2012-04-03 16:20

CaseViewHelper.php Magnifier (1.5 kB) Bastian Waidelich, 2012-04-03 16:20

Associated revisions

Revision 4fd6714d
Added by Bastian Waidelich about 2 years ago

[FEATURE] Switch View Helper

Simple view helper that allows you to render content depending
on a given value or expression.
It bahaves similar to a basic switch statement in PHP.

Usage:

<f:switch expression="{person.gender}">
<f:case case="male">Mr.</f:case>
<f:case case="female">Mrs.</f:case>
</f:switch>

Change-Id: Ibec7b1acc4555a8f69ea7465023a2cf2b06e63aa
Resolves: #33817
Releases: master

Revision 88edf89e
Added by Wouter Wolters about 2 years ago

[BUGFIX] Typo in SwitchViewHelper code example

Fixes a typo in the usage example introduced with
Ibec7b1acc4555a8f69ea7465023a2cf2b06e63aa

Change-Id: Icc23272ed72948a79a09b9b660ac8ed6cca360ac
Fixes: #48856
Related: #33817
Releases: master

History

#1 Updated by Adrian Föder over 3 years ago

additionally, I would prefer dropping "break" support because its use is also pretty ugly in "real" situations imho.

#2 Updated by Bastian Waidelich over 3 years ago

  • Status changed from New to Accepted
  • Assigned To set to Bastian Waidelich

Hi, that's already on my (longish) todo list. I agree with your two points on the magic "default" and break.

#3 Updated by Bastian Waidelich over 3 years ago

Attached a first version that works in general but has side effects when used nested - so it still needs some adjustments

#4 Updated by Gerrit Code Review about 2 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20787

#5 Updated by Gerrit Code Review about 2 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20787

#6 Updated by Bastian Waidelich about 2 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF