Underscore Conditionals in Template
问题 Here is my template: var tmpl = _.template('<<%= elementTag %> <% if (_.has(elementClass)) { %> class="<%= elementClass %>" <% } %> <%= elementExtra %>><%= template(elementContent) %></<%= elementTag %>>'); Some of the objects that I will render using this template my not have an elementClass attribute set. I've tried to use _.has so that the template only attempts to print the attribute for objects where elementClass is defined but I have had no success. The console error states only that