Question

I'd like to do the following in Haml-Coffee:

- case msg.type
- when "usertext"
    = msg.body          
- when "direct"
    = msg.content.kbcontent_body

But I get an error "Reserved word "case""

I suspect it's not supported by Haml-Coffee actually.

Was it helpful?

Solution

There isn't a case statement in CoffeeScript. You want switch — the case keyword is the JavaScript equivalent of when, and like many dropped JavaScript keywords is reserved in CoffeeScript. Also, I'm not 100% positive and don't have Haml-Coffee to test right now, but I think you'll need to indent the body of the switch.

OTHER TIPS

Before the question was edited, it's main phrase had been:

Is there a case statement in HAML?

The answer is: in vanilla Haml there indeed is case!

%p
  - case 2
  - when 1
    = "1!"
  - when 2
    = "2?"
  - when 3
    = "3."
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top