5

I am trying to add a small amount of logic to one of my templates (please don't scold me on the faults of putting logic in the view) and am having a hard time getting the correct hamlc syntax.

I am iterating over a collection and want to skip elements that exist in another collection

The straight up coffeescript would look like:

for artwork in artworks
  unless _.find(cart_items, (ci) ->
    ci.id == artwork.product_code
      alert 'artwork not in cart'

I'm trying:

- for artwork in artworks
  - unless _.find(cart_items, (ci) -> | # < multiline, right?
    ci.id == artwork.product_code
    - alert 'artwork not in cart'

and am getting some hogwash about:

Block level too deep in line undefined

Any ideas? TIA, Billy

Billy
  • 563
  • 5
  • 15
  • In the `I'm trying` section, if it a haml file, or coffeescript file? Which interpreter are you running? – asawyer Jun 05 '12 at 17:52
  • Ah, right, thanks. It's a hamlc file - https://github.com/9elements/haml-coffee. My rep is crap so I couldnt add the hamlc tag.. ;) – Billy Jun 05 '12 at 17:56
  • 1
    I have not seen this before, thanks I'll check it out. Added the tag for you. – asawyer Jun 05 '12 at 17:57

1 Answers1

1

I was able to get this to work by putting the closure on the same line:

- for artwork in artworks
  - unless _.find(cart_items, (ci) -> ci.id == artwork.id)
    - alert 'not in the cart'
Billy
  • 563
  • 5
  • 15
  • 1
    Haml-Coffee had a bug concerning multi-line support, which has been fixed. In addition, according to the Haml documentation, the multi line character (`|`) must also be placed on the last line. – Netzpirat Jul 02 '12 at 15:36