Drum Drum - 1 year ago 161
Node.js Question

Jade Case Statement

I'm trying to use a case statement in a Jade template to set the background colour on a table row, but I am getting an error which I can't seem to pin down.

This is the code:

each photog, i in thelist.ptlist
case photog.currentStatus
when "green": tr(style="background-color:#9f9")
when "amber": tr(style="background-color:#ff9")
when "red": tr(style="background-color:#f99")
default: tr(style="background-color:#99f")

The error I am getting is "Unexpected token 'tag', expected 'when', 'default' or 'newline'" indicating the "td." I tried adding a blan line before the td, but I get exactly the same error.

I have tried the slight variants in layout/syntax that the documentation gives, but to no avail. Would someone please tell me where I am going wrong?

Answer Source

The td tag is aligned with the default thus making it inherited by case statement. Put td outside the case by removing the extra whitespaces.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download