CASE

Note

  • CASE is an object type (= complex data type).

  • It is a specific cObject data type.

This is a very flexible object whose rendering can vary depending on a given key. The principle is similar to that of the "switch" construct in PHP.

The value of the "key" property determines, which of the provided cObjects will finally be rendered.

The "key" property is expected to match one of the values found in the "array of cObjects". Any string can be used as value in this array, except for those that match another property. So the forbidden values are: "if", "setCurrent", "key", and "stdWrap". "default" also cannot be used as it has a special meaning: If the value of the "key" property is not found in the array of cObjects, then the cObject from the "default" property will be used.

Properties

(array of cObjects)

array of cObjects
Data type

cObject

Array of cObjects. Use this to define cObjects for the different values of key. If key has a certain value, the according cObject will be rendered. The cObjects can have any name, but not the names of the other properties of the cObject CASE.

cache

cache
Data type

cache

See cache function description for details.

default

default
Data type

cObject

Use this to define the rendering for those values of key that do not match any of the values of the (array of cObjects). If no default cObject is defined, an empty string will be returned for the default case.

if

if
Data type

->if

If if returns false, nothing is returned.

key

key
Data type

string / stdWrap

Default

default

The key, which determines, which cObject will be rendered. Its value is expected to match the name of one of the cObjects from the array of cObjects; this cObject is then rendered. If no name of a cObject is matched, the cObject from the property default is rendered.

This property defines the source of the value that will be matched against the values of the (array of cObjects). It will generally not be a simple string, but use its stdWrap properties to retrieve a dynamic value from some specific source, typically a field of the current record. See the example below.

setCurrent

setCurrent
Data type

string / stdWrap

Sets the "current" value.

stdWrap

stdWrap
Data type

stdWrap

stdWrap around any object that was rendered no matter what the key value is.

Example:

If in this example the field header turns out not to be set ("false"), an empty string is returned. Otherwise TYPO3 chooses between two different renderings of some content depending on whether the key field layout is "1" or not (default).

The result is in either case wrapped with |<br>.

EXT:site_package/Configuration/TypoScript/setup.typoscript
stuff = CASE
stuff.if.isTrue.field = header
# This value determines, which of the following cObjects will be rendered.
stuff.key.field = layout

# cObject for the case that field layout is "1".
stuff.1 = TEXT
stuff.1 {
    # ....
}
# cObject for all other cases.
stuff.default = TEXT
stuff.default {
    # ....
}

stuff.stdWrap.wrap = |<br>