Feature #33817

SwitchViewHelper

Added by Adrian Föder over 9 years ago. Updated over 8 years ago.

Status:
Resolved
Priority:
Could have
Category:
ViewHelpers
Target version:
-
Start date:
2012-02-09
Due date:
% Done:

100%

Estimated time:
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>


Files

SwitchViewHelper.php (2.68 KB) SwitchViewHelper.php Bastian Waidelich, 2012-04-03 16:20
CaseViewHelper.php (1.5 KB) CaseViewHelper.php Bastian Waidelich, 2012-04-03 16:20
#1

Updated by Adrian Föder over 9 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 9 years ago

  • Status changed from New to Accepted
  • Assignee 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 9 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 over 8 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 over 8 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 over 8 years ago

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

Also available in: Atom PDF