Typoscript approvements in TYPO3 >4

Ok this is a bit late, but I recently noticed that there are some improvements in the TypoScript language: You can use the new operator ":=" in combinition with some functions.

This is especially very helpful to manipulate liststrings, e.g. to adjust configuration of the RTE.

 

I just copy and paste the relevant section from
typo3.org/documentation/document-library/core-documentation/doc_core_ts/4.1.0/view/1/2/
here:

Value modifications: The ":="-operator

assigns a value to an object path by calling a predefined function which modifies the existing value of the current object path in different ways.

This is very useful for extending lists of page IDs etc. when a value should be extended without redefining it completely again.

Rules:

  1. The portion after the “:=”-operator and to the end of the line is split in two parts: A function and a value. The function is specified right next to the operator (trimmed) and holding the value in brackets (not trimmed).
  2. There are four predefined functions:
    1. prependString: Adds a string to the beginning of the existing value.
    2. appendString: Adds a string to the end of the existing value.
    3. removeString: Removes a string from the existing value.
    4. replaceString: Replaces old with new value. Separate these using “|”.
    5. addToList: Adds a comma-separated list of values to the end of a string value. There is no check for duplicate values, and the list is not sorted in any way.
    6. removeFromList: Removes a comma-separated list of values from a comma-separated list.

 There is a hook inside class.t3lib_tsparser.php which can be used to define more functions like this.

Example:

myObject = TEXT
myObject.value = 1,2,3
myObject.value := addToList(4,5)
myObject.value := removeFromList(2,1)


...results in the same like this:
myObject = TEXT
myObject.value = 3,4,5

blog comments powered by Disqus
blogroll