Using stdWrap correctly

The stdWrap function is one of the most powerful and most widely used of all TypoScript. Most properties actually support stdWrap turning each of them into some kind of Swiss army knife.

stdWrap is very rich, having itself a large number of properties. This chapter is intended to give you a feel for stdWrap so that you may get familiar with it and be ready to explore it in greater depth using the TypoScript Reference.

Details of stdWrap

Heed the order

The single most important thing to know about stdWrap is that all properties are parsed/executed exactly in the order in which they appear in the TypoScript Reference, no matter in which order you have set them in your TypoScript record.

Let's consider this example:

10 = TEXT
10 {
  value = typo3
  noTrimWrap = |<strong>Tool: |</strong>|
  case = upper
}
Copied!

It results in the following:

<strong>Tool: TYPO3</strong>
Copied!

The case property is executed before the noTrimWrap property. Hence only "typo3" was changed to uppercase and not the "Tool:" with which it is wrapped.

Modify the order

There is a way around this ordering restriction. stdWrap has a property called orderedStdWrap in which several stdWrap properties can be called in numerical order. Thus:

10 = TEXT
10 {
  value = typo3
  orderedStdWrap {
    10.noTrimWrap = |<strong>Tool: |</strong>|
    20.case = upper
  }
}
Copied!

results in:

<strong>TOOL: TYPO3</strong>
Copied!

because we explicitly specified that noTrimWrap should happen before case.

It should be noted that stdWrap itself has a stdWrap property, meaning that it can be called recursively. In most case orderedStdWrap will do the job and is much easier to understand making code easier to maintain.

The data type

While writing TypoScript, it is crucial to know what kind of data type you are handling. It is common to see beginners try to combine functions arbitrarily, until the anticipated result is finally achieved by accident.

The TypoScript reference is very clear about which properties exist and what their data type is, so please refer to that essential resource while writing your TypoScript configuration.

cObject

The stdWrap property "cObject" can be used to replace the content with a TypoScript object. This can be a COA, a plugin or a text like in this example:

10.typolink.title.cObject = TEXT
10.typolink.title.cObject {
  value = Copyright
  case = upper
}
Copied!