Reputation: 5281
I want to iterate through a JSON object array and create a table using underscore and jade but my jade template is throwing me the following error and I haven't been able to find any resources to fix it.
Error: /home/kseguy/node_projects/prwrite/views/dashboard/index.jade:69
67| script(type="text/template" ,id="data-table")
68| <% _.each(article,function(article){ %>
> 69| tr
70| td <%= article.ProjectName %>
71| td <%= article.Date %>
72| td <%= article.Status %>
unexpected token "indent"
at Parser.parseExpr (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:252:15)
at Parser.block (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:707:25)
at Parser.tag (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:816:24)
at Parser.parseTag (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:737:17)
at Parser.parseExpr (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:211:21)
at Parser.block (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:707:25)
at Parser.tag (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:816:24)
at Parser.parseTag (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:737:17)
at Parser.parseExpr (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:211:21)
at Parser.block (/home/kseguy/node_projects/prwrite/node_modules/jade/lib/parser.js:707:25)
How can I debug the issue ? I have already tried converting indentation to tabs and spaces using sublime text but so far no success.
Here is my jade template
tbody
script(type="text/template" ,id="data-table")
<% _.each(article,function(article){ %>
tr
td <%= article.ProjectName %>
td <%= article.Date %>
td <%= article.Status %>
td <%= article.Url %>
<% }); %>
Upvotes: 1
Views: 254
Reputation: 13495
This does work since jade treats things starting with < as regular text. But you must be careful as it is not possible for them to have children, so lines beneath them can not be further indented.
Here is a jade test with normal comments, that you could then replace with underscore
// http://jsfiddle.net/smwpvngc/2/
<template>
script
<!-- each -->
tr
td <!-- col1 -->
td <!-- col2 -->
td <!-- col3 -->
<!-- close each -->
</template>
Output:
<script>
<!-- each --> <tr><td><!-- col1 --></td><td><!-- col2 --></td>
<td><!-- col3 --></td></tr><!-- close each --></script>
If I add an additional space before the tr, I also get an indent error as jade does not know how to fill a raw entry with children.
Upvotes: 1