Search code examples
syntaxcoffeescripthamlhamlc

How do I make a haml-coffee closure which spans multiple lines?


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


Solution

  • 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'