0
votes

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

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 - seebiscuit
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 - Robert Levy

1 Answers

2
votes

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