Cast Iron Coding, Inc

TYPO3 Admin's Corner

Click here to return to the TYPO3 Admin's Corner

Stay Connected

Complete the form below to sign up for the CIC newsletter. We send out about one message each month and we do our best to make sure it's full of useful information about TYPO3. We'll never share your email address with a third-party and should you ever change your mind, unsubscribing is a breeze.
TypoScript Techniques

Understanding optionSplit

A fresh look at the basics of the TypoScript optionSplit expression.

By: Lucas Thurston

The TSref optionSplit entry serves well as an introduction to a powerful tool available to Typoscript. Despite its numerous examples to aid in clarifying the unfortunate terminology (What's the practical difference between a subpart and part? What does "the first part of the last value is repeated before the last value" mean?), it left me more curious than confident. I was ready to try some experiments of my own. My main goal was the find the boundaries of the optionSplit expression and to see if those boundaries helped in understanding the optionSplit rules. If possible, it would also be nice to have some sort of shorthand to represent patterns that can be rendered using optionSplit so that one could quickly and easily locate the expression need to render it. Let's quickly look at some terminology so we're talking about the same thing.

An optionSplit expression is one-line string with a number of splitters or dividers organizing substrings into a hierarchy. We can call the full string the optionSplit expression or just the string.

The TSref uses the terms "parts" and "subparts" to break this main expression down into relevant pieces. A "part" is a subexpression as determined by the location(s) of the |*| splitter. A "subpart" is a part that has been further broken down by the || splitter, and contains no further optionSplit operators.

The TSref does well to demonstrate the purpose of optionSplit. In the simplest terms it is to provide a controlled structure for assigning attributes or values to a list of items (usually titles of pages for a menu) according to the number of items in the list. This is achieved with two types of dividers or splitters, which each split and prioritize the options according. The first divider is two horizontal lines: ||. It, according to the TSref, subdivides the first, middle and last into subparts and we'll call it the "subparts divider." This divider can, in reality, split more than three strings. The first, middle, and last parts are split using the second divider: |*|. This is the "parts divider," however, it might be easier to call it the "FML divider" (first, middle, last) since, as we shall see, this divider can only occur twice in an optionSplit expression, and therefore only splits the first, middle and last. The subparts divider, as previously mentioned, can occur any number of times in an expression, something that is not explicited said about these dividers. Clearly neither NEEDS to occur in any expression, as demonstrated by one of the first examples in the TSref:

temp.topmenu.1.NO {
backColor = red ....
}

Posted on Friday, August 26, 2005 at 12:54 PM.