What is causing SyntaxError: Unexpected EOF error in underscore template?

24,886

Looks like you didn't close <%= with %>

Share:
24,886
SamBrick
Author by

SamBrick

I'm a full-stack developer with specialist skills in interactive design, UI and UX. My focus is on Javascript, in particular React, Redux and Node. I also have experience with AWS services such as Lambda, Cognito and API Gateway.

Updated on April 27, 2020

Comments

  • SamBrick
    SamBrick about 4 years

    I am getting a SyntaxError: Unexpected EOF output when using an underscore template to render html in a Backbone application. Here is my template:-

    <script type="text/template" id="shellmenu-template">
      <div>
        <p>menu template html will go here....</p>
        <div class="menuButtonsContainer">
            <% _.each(menu, function(menuItem){ %>
            <button class="menuButton" id="<%= _.escape(menuItem.id)"><%= _.escape(menuItem.title) %></button>
            <% }); %>
        </div>
      </div>
    </script>
    

    It is specifically erroring on this part:-

    id="<%= _.escape(menuItem.id)"
    

    The id attribute is a number, here is the menuItem object:-

    dataPath: ""
    helpType: "default"
    id: 0
    moduleName: "TestModule"
    modulePath: "interaction/test/testmodule"
    title: "Test Module Interaction"
    

    I have tried making the id a string or making it the title attribute in the underscore template code just to see if I can get a test case working in any shape or form but I am stumped so far. I have a similar template doing pretty much the same thing with no errors.

    Any ideas what silliness I am engaging in to cause this? :-)

  • SamBrick
    SamBrick about 11 years
    Wow. Facepalm. Thanks a lot @neo :-)