blueimp/JavaScript-Templates

Return empty string instead of "undefined" on non-existent variables

Mark-H opened this issue · 2 comments

On line 69 (first line of tmpl.encode) I added this super simple patch to return an empty string instead of the string "undefined" when a specific value is not passed to the function.

if (!s) return '';

Figured I'd at least put it out here in case others are looking for the same thing, and maybe it's something you want to include (or know a more correct way for).

Thanks for a super simple-to-use, slim and awesome lib.

This was actually the previous behavior before commit 6ad43cf

Maybe it makes sense to selectively print out falsy values like 0 and false but not null or undefined.

And your preferred behavior was introduced with this previous commit: 5614516

So yeah, since both is desired and the easy solution doesn't solve both, I will have to introduce selective output of falsy values.