Nested 'if' conditions in ESPhome action?

The esphome code should be in the form

lambda: |-
  if (expression){statement}
  else if (expression){statement}
  else {statement}

Exactly like the example. I think it might only be valid code without the !lambda