1
votes

I'm working on Addy Osmani's Backbone Fundamentals tutorial. http://addyosmani.github.io/backbone-fundamentals/#application-view

and am getting an "Uncaught SyntaxError: Unexpected token % " in Chrome.

It's pointing to a line in Underscore.js and also a line in my views/app.js.

In views/app.js, the line it's pointing to is:

statsTemplate: _.template( $('#stats-template').html() ),

It says "anonymous function" in the error message. This was copied from the tutorial, so I'm not sure why it's throwing an error. Thanks

Template markup:

<script type="text/template" id="stats-template">
    <span id="todo-count">
       <strong>
           <%= remaining %>
       </strong>
       <%= remaining === 1 ? 'item':'items'%> left
    </span> 
    <ul id="filters">
        <li> 
            <a class="selected" href="#/">All</a> 
        </li> 
        <li> 
            <a href="#/active">Active</a> 
        </li> 
        <li> 
            <a href="#/completed">Completed</a>
        </li> 
    </ul>
    <% if(completed) {% >
        <button id="clear-completed">Clear completed (<%= completed %>)</button> 
    <% } %> 
</script>
1
What does $('#stats-template').html() contain? Looks like a syntax error in there. - Bergi
Implies a syntax error in the stats-template markup -- please post. - McGarnagle
Ah, ok. Here's the stats-template code <script type="text/template" id="stats-template"> <span id="todo-count"><strong><%= remaining %></strong><%= remaining === 1 ? 'item':'items'%> left</span> <ul id="filters"> <li> <a class="selected" href="#/">All</a> </li> <li> <a href="#/active">Active</a> </li> <li> <a href="#/completed">Completed</a> </li> </ul> <% if(completed) {% > <button id="clear-completed">Clear completed (<%= completed %>)</button> <% } %> </script> - gh0st

1 Answers

5
votes

The template markup has a space between % and > which is causing Underscore to balk. This:

<% if(completed) {% >

Should be this:

<% if(completed) { %>

Fiddle