<%= and <%- output null#559
Conversation
|
I'm not a fan of the fix for interpolate (bfc7639), though it is simple and does pass the tests. But maybe there is a more elegant solution. |
|
I've added a In doing so, I also added similar support (for I did not create a minified version. I stick to |
|
It seems like you are adding type/value tests to a function purposed for blindly escaping HTML characters. Would it not make more sense to check the variable type/value before passing it to the template in your own code? I understand why you might want |
|
@octatone, Yeah, I agree about Then again, I hate that I've moved the code for that into the <form>
<table>
<tr>
<th>Name</th><th>Email</th>
</tr>
</table>
<button id="add_another">+ Add Another</button>
</form>
<script type="text/html" id="user_form">
<tr>
<td><input type="text" name="user-<%= index %>-name" value="<%- user.name %>" /></td>
<td><input type="text" name="user-<%= index %>-email" value="<%- user.email %>" /></td>
</tr>
</script>
<script type="text/javascript">
var data = [
{name: 'Colin', email: 'colinta@gmail.com' }
, {name: null, email: null }
, {}
]
, template = _chz.user_form;
_(data).each(function(row, index) {
$('table').append(template({user: row, index: index}));
});
$('#add_another').on('click', function() {
var index = $('table tr').length - 1;
$('table').append(_chz.user_form({user: {}, index: index }}));
return false;
});
</script>
```html
I would expect this to result in:
```html
<form>
<table>
<tr>
<th>Name</th><th>Email</th>
</tr>
<tr>
<td><input type="text" name="user-0-name" value="Colin" /></td>
<td><input type="text" name="user-0-email" value="colinta@gmail.com" /></td>
</tr>
<tr>
<td><input type="text" name="user-1-name" value="" /></td>
<td><input type="text" name="user-1-email" value="" /></td>
</tr>
<tr>
<td><input type="text" name="user-2-name" value="" /></td>
<td><input type="text" name="user-2-email" value="" /></td>
</tr>
</table>
<button id="add_another">+ Add Another</button>
</form>Right now, this code ends up with |
|
I think that the |
|
I know. I cringed when I put that in there, but that was the only way I could come up with that allowed I haven't done a thorough comparison, but a rough one - running the 'utility' tests, puts them neck and neck. I will post a thorough benchmark later today. On Apr 18, 2012, at 7:13 AM, brad dunbarreply@reply.github.com wrote:
|
|
I don't think that we should swallow errors like |
|
It's your call. I would be happy with either of two solutions:
The only solution I am not happy with is when it outputs "null" or "undefined". To me, that is coercing to an incorrect string. |
|
This is a duplicate of the earlier #556 -- so let's move the conversation over there. In any event, we aren't going to add a try/catch to our interpolations. |
actually, in the version I was using in my project,
<%= test %>outputs""when{test:null}. but in the latest underscore, it outputs"null"javascriptconsole.log(_('[<%= test %>] {<%- test %>}').template({test: null}));