[Note: This question is very similar, but not quite the same.]
I’m trying to do if statements with underscore templates. I have tried:
<% if (_id) { %><%=_id %><% } %>
and
<% if (_id) { _id } %>
and
<% if (_id) { <%= _id %> } %>
and a bunch of other combinations, but I always get the error
ReferenceError: _id is not defined
Any suggestions?
I have no idea what is your code, but
_idis obviously an identifier. The problem, though, that you do not have_iddefined.As for suggestion, I’d probably suggest that you define it or use the one that is defined. It’s hard to give you a better suggestion with zero context.
EDIT: you probably want
if(typeof _id != 'undefined')instead.