I have an error parsing an underscore template, I keep getting an error saying:
Uncaught SyntaxError: Unexpected token else
Here is the template below: using Jade
script#viewLinksTemplate(type="text/template")
table.table.table-condensed.table-striped
caption Available links
thead
tr
td link id
td Name
td View
td Edit
td Remove
tbody
{[ _.each(routes, function(route) { ]}
tr
td {{ route._id }}
{[ if (typeof route.name !== 'undefined') { ]}
td {{ route.name }}
{[ } ]}
{[ else { ]}
td {{ route.stations.start.name }} - {{ route.stations.end.name }}
{[ }; ]}
td
a.btn.btn-primary(href="/route") View Route
td
a.btn.btn-warning Edit Route
td
a.btn.btn-danger Delete Route
{[ }); ]}
The problem seems to be in the if/else statement. When I remove it completely the parts that are left on the template are rendered.
So, am I missing something with the syntax? All my other templates have javascript, and render correctly, except this one with the if/else.
Thanks
It's because the end of the if
statement and the else
are in two different evaluate tags. Merge them into one by replacing:
{[ } ]}
{[ else { ]}
with:
{[ } else { ]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With