Code blocks

Curly braces can be used to structure identifier paths in a more efficient way: Without repeating upper parts of a path in each line. This allows nesting.

Example without braces:

Extension examples, file Configuration/TypoScript/Syntax/CodeBlock/setup.typoscript
myIdentifier = TEXT
myIdentifier.stdWrap.field = title
myIdentifier.stdWrap.ifEmpty.data = leveltitle:0
Copied!

This can be written as:

Extension examples, file Configuration/TypoScript/Syntax/CodeBlock2/setup.typoscript
myIdentifier = TEXT
myIdentifier {
   stdWrap.field = title
   stdWrap.ifEmpty.data = leveltitle:0
}
Copied!

Curly braces can be nested to further improve readability. This is also the same as above:

Extension examples, file Configuration/TypoScript/Syntax/CodeBlock3/setup.typoscript
myIdentifier = TEXT
myIdentifier {
   stdWrap {
      field = title
      ifEmpty {
         data = leveltitle:0
      }
   }
}
Copied!

Some rules apply during parsing:

  • Everything on the same line after the opening { and closing } brace is considered a comment, even if the comment markers #, // and /* ... */ are missing.
  • The closing brace } must be on a single line in order to close a block. The following construct is invalid, the closing brace is interpreted as part of the value, so the TypoScript and TSconfig backend modules will mumble with a "missing closing brace" warning:

    Extension examples, file Configuration/TypoScript/Syntax/CodeBlockInvalidClosingBrace/setup.typoscript
    myIdentifier = TEXT
    myIdentifier {
       value = bar }
    Copied!
  • Conditions can not be placed within blocks, they are always "global" level and stop any brace nesting. The following construct is invalid, the TypoScript and TSconfig backend modules will mumble with a "missing closing brace" warning:

    Extension examples, file Configuration/TypoScript/Syntax/CodeBlockInvalidCondition/setup.typoscript
    myIdentifier = TEXT
    myIdentifier {
       value = foo
       [frontend.user.isLoggedIn]
          value = bar
       [end]
    }
    Copied!
  • Nesting is per-file / per-text-snippet: It does not "swap" into included files. This was the case with the old TypoScript parser. It has been a nasty side-effect, leading to hard to debug problems. File includes with @import and <INCLUDE_TYPOSCRIPT: within curly braces are not relative (anymore). A construct like this is invalid, the TypoScript and TSconfig backend modules will mumble with a "missing closing brace" warning:

    Extension examples, file Configuration/TypoScript/Syntax/CodeBlockInvalidCondition/setup.typoscript
    myIdentifier = TEXT
    myIdentifier {
       @import 'EXT:my_extension/Configuration/TypoScript/bar.typoscript'
       value = foo
    }
    Copied!