3

I am using Backbone and Eco templates in my Rails application. My template has the following code:

  <% @collection.each (model)-> %>
    <% console.log model.get('name') %>
    <p><%= model.get('name') %></p>
    <p><%= model.get('description') %></p>
  <% end %>

For some reason, the HTML is blank. The name and description are not displayed. However, the console.log method outputs the correct data. What am I doing wrong?

Andrew
  • 227,796
  • 193
  • 515
  • 708

1 Answers1

4

Well I figured out the missing character. Apparently, Eco templates require a colon after the arrow:

<% @collection.each (model)->: %>

Not sure why this is the case. It's never mentioned in the readme.

Andrew
  • 227,796
  • 193
  • 515
  • 708
  • ["CoffeeScript is whitespace-sensitive, but your templates aren't. Therefore, Eco code tags that begin an indented CoffeeScript block must be suffixed with a colon. To indicate the end of an indented block, use the special tag `<% end %>`."](https://github.com/sstephenson/eco#a-note-about-whitespace) – mu is too short Jul 01 '13 at 23:40
  • Yes, but none of the block examples in the readme adhere to this syntax: https://github.com/sstephenson/eco#blocks-and-capturing – Andrew Jul 01 '13 at 23:53
  • Fair enough. I wonder if the behavior is context sensitive, do you still need the colon if the first thing in the template isn't a `<%...%>`? – mu is too short Jul 02 '13 at 00:05
  • I don't know. I filed an issue on GitHub. It's either a mistake in the documentation or a bug in the behavior. – Andrew Jul 02 '13 at 00:16