0

I'm using Underscore templates with BackBone to display the content. Unfortunately I'm receiving the error:

Uncaught SyntaxError: Unexpected token <

The code is:

                    <script type="text/javascript" id="results-tpl">
                <% if(remainingPlaces>0 && remainingPlaces<10){
                      availability_class = 'limited-availability';
                      bookable = 'booking__bookable';
                  }
                  else if(remainingPlaces>9)
                  {
                      availability_class = 'available';
                      bookable = 'booking__bookable';
                  }
                  else{
                      availability_class = 'sold-out';
                      bookable = '';
                  }%>
                  <div class='booking__event__availability__box' data-eventID='<%-ID%>'>
                        <span class='time <%=availability_class%>  <%=bookable%>'><%=startTime%></span>
                        <span class='availability'><%=(remainingPlaces>0 && remainingPlaces<10) ? 'Only' : ''%> <%=remainingPlaces%> left</span>
                  </div>
                </script>

I can't seem to figure out why I'm getting the error.

Any help would be appreciated.

Cheers,

Nick

2
  • 1
    Add the line <%debugger%> with your debugger (Google Dev, Firebug) open and then step through your code until you find where it errors out. If you're still having issues update your question Commented Dec 17, 2014 at 14:08
  • unrelated but might as well give feedback... having an if block in a template that modifies the model isn't really a good practice. you should do these calculations and adjustments to the model within the view JS or in the model's parse() function. the template should be purely focused on rendering Commented Dec 17, 2014 at 14:28

1 Answer 1

2

<script type="text/javascript" id="results-tpl"> replace type with: text/template

Sign up to request clarification or add additional context in comments.

2 Comments

I don't that's the source of the error. All <%- does is escape html in the return value of the evaluated variable. A variable with a name like ID is most likely a GUID an int, each of which wouldn't cause the OP's problem
@nvaughan84 in my case i store all templates in separate html files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.