I am looking to move my application from JavaScriptMVC to CanJS and am noticing some issues with EJS templates I had written previously that worked in JMVC but not in CanJS. Are there any specific guidelines for writing templates? For instance I thought the following would work
For instance this worked in JavaScriptMVC
- <% for(var i = grouped.length - 1; i >= 0; i--){
- var facetGroup = grouped[i];
- for(var j = facetGroup.length - 1; j >= 0; j--){ %>
- <a href=""><%== facetGroup[j].label %></a>
- <% if(j != 0){
- %> or <%
- }
- }
- if(i != 0){
- %> > <%
- }
- }
but had to be reformatted as follows to work in CanJS
- <% for(var i = grouped.length - 1; i >= 0; i--){
- var facetGroup = grouped[i];
- for(var j = facetGroup.length - 1; j >= 0; j--){ %>
- <a href=""><%== facetGroup[j].label %></a>
- <% if(j != 0){ %>
- or
- <% } %>
- <% }
- if(i != 0){ %>
- >
- <% } %>
- <% } %>
While this seems to be a subtle difference I really do not understand why this was required. Also what is the best way of debugging templates? I get cryptic errors like "Uncaught SyntaxError: Unexpected token if", how do others track down issues when dealing with templates that have a bit of logic in it?