Error 'unrecognized expression' when template is empty #111

Closed
rdogmartin opened this Issue Apr 19, 2012 · 2 comments

Comments

Projects
None yet
2 participants

When a script template is empty, the render function results in the error 'unrecognized expression'. For example:

  <script id="movieTemplate" type="text/x-jsrender">
  </script>
  <div id="movieList"></div>
  <script type="text/javascript">

    var movies = [
        { name: "The Red Violin", releaseYear: "1998" },
        { name: "Eyes Wide Shut", releaseYear: "1999" },
        { name: "The Inheritance", releaseYear: "1976" }
    ];

    $("#movieList").html($("#movieTemplate").render(movies));

  </script>

I suggest that the render call should return an empty string and not throw an error.

If you're wondering why I have an empty template, it's because I have an app where users can define their own templates which are stored in the DB. In many cases they will leave them empty. I could add a few extra lines of code to call render only when the template is not empty, but it would be cleaner (and more intuitive) for the render method to simply return an empty string.

Regards,
Roger Martin
Gallery Server Pro
www.galleryserverpro.com

Owner

BorisMoore commented Apr 19, 2012

Thanks for pointing this out.
In fact your script block is not empty - it has new line. What was happening was with white space only the test for a jQuery selector was throwing in sizzle code.
This is fixed in pre-beta #5, and will now render with whatever the content is, including white space... If the template is the empty string, it will render the empty string...

@BorisMoore BorisMoore closed this Apr 19, 2012

Thanks - your change works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment