Feature #33817
SwitchViewHelper
| 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>
  Associated revisions
[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
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
- File SwitchViewHelper.php added added
- File CaseViewHelper.php added added
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
Applied in changeset 4fd6714dd228e34fe2603dd1920ea2684c602eef.