Documentation · ViewHelper reference

SwitchViewHelper


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

Simple Switch statement

<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


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.
  • Tag usage example

    <f:switch expression="[mixed]">
    	<!-- tag content - may be ignored! -->
    </f:switch>
  • Inline usage example

    {f:switch(expression: [mixed])}

Arguments

Argument Description Type
expression mixed
Required attribute

Revision history

commit 9fdbc9569b70aefd04c09d5a80cc6c2abde50283
Author: Claus Due <*****@wildside.dk>
Date:   Fri Nov 2 17:10:02 2012 +0100

    [FEATURE] Switch and Case ViewHelpers

commit 0b0d58e31a7fe760acee5ec46b373596d225ecc1
Author: Claus Due <*****@wildside.dk>
Date:   Wed Jan 2 14:02:58 2013 +0100

    [DOC] Use Markdown in Doc Comments (1)
    
    Work in progress to be committed in smaller chunks. All Doc Comments are being turned into Markdown syntax for automatic rendering in online documentation.

commit da31bad1d9bb058c072ddb5591e8ed907a1ae8e1
Author: Claus Due <*****@namelesscoder.net>
Date:   Tue Dec 31 23:08:37 2013 +0100

    [TASK] Happy new year!

commit d2e531da034976e6db1478eef5a8478595fd16fe
Author: Claus Due <*****@namelesscoder.net>
Date:   Sun Jan 5 00:45:10 2014 +0100

    [TASK] Migrate to using namespace core class names

commit 52bd6e41ccfef3d8193b350153912a9716e6a087
Author: Benjamin Rau <*****@codearts.at>
Date:   Tue Apr 1 21:09:00 2014 +0200

    [TASK] CGL compliance

commit da7677bc74f14e9a9300e4ba4487e52c3cb97642
Author: Claus Due <*****@namelesscoder.net>
Date:   Sun Apr 20 01:13:33 2014 +0200

    [TASK] Switch to namespaces

commit 12ff0ddfb8d36c51f2d3befde7ae812177c80d5d
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Wed Jun 11 00:01:47 2014 +0200

    [TASK] CGL remove use leading backslash
    PHP Docs
    Note that for namespaced names (fully qualified namespace names containing namespace separator, such as Foo\Bar as opposed to global names that do not, such as FooBar),
    the leading backslash is unnecessary and not recommended, as import names must be fully qualified, and are not processed relative to the current namespace.

commit 4981055359c895f3869e5bd878293b3c15ed26e5
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Sun Jan 18 14:01:04 2015 +0100

    [TASK] CGL - Define classes, params, use imports

commit 8bb2fc5ee124ba19b0a0ab8e061c9a153fc4651f
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Sun Jan 18 17:56:13 2015 +0100

    [TASK] Reference Copyright to license.md file