Search code examples
node.jsexpresspug

Conditional statements in express / jade


I am trying to use nested conditional statements in jade, but keep getting syntax error.

The following works:

if condition != true
  p Hello
  p Hello

But when I try add a nested condition, it fails:

if condition != true
  p Hello
  if other == true
    p Other
  p Final

I am trying to get the equivalent of:

if (condition != true) {
  p Hello
  if (other == true) {
    p Other
  }
  p Final
}

Depending on my indenting, the 2nd if is either literally translated or I get errors about p Final.


Solution

  • Found an alternative approach to this:

    - var content = ""
    if other
      content = "Foo"
    
    if condition
      p Hello
      #{content}