0

Specific question: this code works in a backbone template index.jst.eco, but it doesn't work in index.jst.ejs

<ui>

<% for entry in @entries.models: %>
<li> <%= entry.get('name') %></li>
<% end %>

</ui>

I'd like to know why (i.e. how to fix it for ejs), and, more generally, is there comprehensive documentation for how to write code in ejs templates? I can't find anything that goes into detail. As I've been playing around with ejs and eco, I've noticed the presence or absence of a : or a bracket can make a huge impact but I can't figure out how to know what to use and when.

I'm willing to use jst.eco or jst.ejs depending on which syntax has better documentation.

Leahcim
  • 40,649
  • 59
  • 195
  • 334

3 Answers3

1

Just encountered this problem, here's my solution!

<% entries.each(function(entry){%>
  <li><%= entry.get('name') %></li>
<% });%>
Fiona T
  • 1,921
  • 1
  • 15
  • 18
0

This is how that eco code would be written in jst.ejs.

   <% for (var i = 0; i < entries.length; i++) { %>
    <li> <%= entries.models[i].get('name') %></li>
    <% } %>

However, I can't get it to work with a for entry in entries.models iterator

Leahcim
  • 40,649
  • 59
  • 195
  • 334
0

From what I've known, jst.eco format is CoffeeScript embedded into jst template, and jst.ejs will only work with JavaScript. That's why in your case it can render this JavaScript iteration:

<% for (var i = 0; i < entries.length; i++) { %>

but not this CoffeeScript interation:

<% for entry in @entries.models: %>