Underscore template returns nothing: why?

82 Views Asked by At

This template has a spelling error in the first if statement, and it returns nothing. When I place a debugger statement in this template, it gets to the first if statement, then dies. Examining __p shows me valid javascript, so I'm confused on why the whole templating function is returning nothing.

If identifer is undefined (it's not passed to the template function; only the correct identifier placeholder is), shouldn't it log an error to the console, stating that the variable I am trying to compare is undefined?

<h3>This is the <%= identifier %> for the thing.</h3>
<% if (identifer === "something") { // spelling error in this line. %>
  <p>It is something.</p>
<% } else if (identifier === "something else") { %>
  <p>It is something else.</p>
<% } else { %>
  <p>The <%= identifier %> is something completely different.</p>
<% } %>

<div>
  <p>Some other HTML follows</p>
</div>

The template just dies, with no indication of what's wrong, and this seems weird to me. Any ideas why Underscore templates work this way?

2

There are 2 best solutions below

1
On BEST ANSWER

Change this line in the template from <% if (identifer === "something") { %> to <% if (identifier === "something") { %>

0
On

It turns out that my Firefox Developer console (on 38.05 currently) was not set up to log javascript errors to the console. I had to open the console, click the disclosure triangle on the 'JS' button, and the put a check mark next to 'Errors'.

I'm assuming that this was something that I turned off in the past, by mistake. I turned it on, and all of the undefined errors are appearing exactly as I would expect them to.