Search code examples
selecttypo3conditional-statementstyposcript

Typoscript: how to select a set of subpages or how to make a condition based on page id


Currently I'm working with PIDinRootline. This works fine.

[PIDinRootline=8,9]
    //do something
[end]

[PIDinRootline=6,7,11]
    //do something
[end]

Now I want to address a set of subpages under 7. Currently an all pages where the parent has the id 7 has the same code. But now I want something different on page id 128 and all its subpages. Is it allowed to make something like

[PIDinRootline=8,9]
    //do something
[end]

[PIDinRootline=6,7,11]
    //do something different
[end]
[PIDinRootline=128]
    //do something
[end]

So the page 128 is under 7. The setting is overwritten because first the settings from PIDinRootline=7 takes place and then the settings from PIDinRootline=128. Is this allowed?


Solution

  • Definetely allowed. Just make sure you define conditions in the same order as quoted. You can actually leave out some of the [end] conditions. Note: This works for TYPO3 up to version 8 / 9.3:

    [PIDinRootline=8,9]
        //do something
    [PIDinRootline=6,7,11]
        //do something different
    [PIDinRootline=128]
        //do something
    [end]
    

    The old condition syntax was deprecated with TYPO3 9.4. The new syntax is based on the symfony expression language and looks like this:

    [8 in tree.rootLineIds || 9 in tree.rootLineIds]
        //do something
    [6 in tree.rootLineIds || 7 in tree.rootLineIds || 11 in tree.rootLineIds]
        //do something different
    [128 in tree.rootLineIds]
        //do something
    [end]
    

    Other useful page related conditions are (old syntax):

    • [globalVar = TSFE:id = 128] // Only on PID 128
    • [PIDupinRootline = 128] // Only on subpages of PID 128 (PID 128 not included)
    • [treeLevel = 1] // All pages that belong to tree level 1 (subpages of root level)

    Check the TYPO3 reference for the new condition syntax.