Search code examples
typoscript

TypoScript Condition Syntax


I am new to Typo3 and TypoScript. I try a simple condition, but I fail: I NEED HELP!

My condition:

["HELP" == "HELP"]
  templateName = Root
[else]
  templateName = Sub
[end]

The condition is in a FLUIDTEMPLATE on a Page:

page = PAGE
page {
  ...
  10 = FLUIDTEMPLATE
  10 {
    ...
    ["HELP" == "HELP"]
      templateName = Root
    [else]
      templateName = Sub
    [end]
    ...
  }
  ...
}

I also tried

templateName = Root
["HELP" == "ELP"]
templateName = Sub
[END]

I was not able to find an understandable explanation.

I tested it with line comments, but it seems it executes both cases always.


Solution

  • As the indention is just a shortcut in TypoScript you can't insert conditions on other levels than root.

    the correct syntax to your example would be:

    page = PAGE
    page {
      ...
      10 = FLUIDTEMPLATE
      10 {
        ...
        templateName = Sub
        ...
      }
      ...
    }
    ["HELP" == "HELP"]
      page.10.templateName = Root
    [else]
      page.10.templateName = Sub
    [end]
    

    If you have defined the default value above you could omit the else part.