Underscore: Templates broken in 1.7

Created on 8 Nov 2014  ·  5Comments  ·  Source: jashkenas/underscore

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.

invalid

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... :(

All 5 comments

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... :(

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grignaak picture grignaak  ·  16Comments

park9140 picture park9140  ·  38Comments

dmaicher picture dmaicher  ·  9Comments

afranioce picture afranioce  ·  8Comments

wilhen01 picture wilhen01  ·  32Comments