It seems like the API for templates changed. Not sure if that is considered a feature, but I would consider it a bug as it breaks everything I have ever done with underscore templates.
The issue is that I can no longer pass in data and get the rendered template back. It now returns a function instead of a string.
According 1.7 changelog: "Underscore templates no longer accept an initial data object. _.template always returns a function now". So this is the change without backward compatibility.
Right. Isn't that a terrible idea? What if someone has server side templating with node.js and they unwittingly update to underscore 1.7? They are screwed. Why not just check whether an object is a settings object or a data object based on what keys the object has?
See https://github.com/jashkenas/underscore/issues/1736 for reasoning, and https://github.com/jashkenas/underscore/issues/1805 for arguments that underscore should be following semver.
Either way, you can update your own code to _.template(templateStr)(data)
.
It wasn't a question of how to work around the issue. I am actually embracing the change. Without considering all of the code this breaks, from a performance and API perspective it makes sense. It was just a rude surprise to update my node server and have my email templates stop working.
Thanks for pointing out the other issue threads. I enjoyed reading the discussions.
And I thought if there was one js library I wound't have compatibility problems would be underscore.... and in a minor version !!! there are no excuses for this... :(
Most helpful comment
And I thought if there was one js library I wound't have compatibility problems would be underscore.... and in a minor version !!! there are no excuses for this... :(