Skip to content

Commit 4809f7f

Browse files
committed
Fixes jashkenas#1736 -- Underscore templates no longer accept a data argument -- just settings.
1 parent 7ff2fde commit 4809f7f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

test/utility.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@
271271
test('_.templateSettings.variable', function() {
272272
var s = '<%=data.x%>';
273273
var data = {x: 'x'};
274-
strictEqual(_.template(s, data, {variable: 'data'}), 'x');
274+
var tmp = _.template(s, {variable: 'data'});
275+
strictEqual(tmp(data), 'x');
275276
_.templateSettings.variable = 'data';
276277
strictEqual(_.template(s)(data), 'x');
277278
});

underscore.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,9 @@
12831283
// JavaScript micro-templating, similar to John Resig's implementation.
12841284
// Underscore templating handles arbitrary delimiters, preserves whitespace,
12851285
// and correctly escapes quotes within interpolated code.
1286-
_.template = function(text, data, settings) {
1286+
// NB: `oldSettings` only exists for backwards compatibility.
1287+
_.template = function(text, settings, oldSettings) {
1288+
if (!settings && oldSettings) settings = oldSettings;
12871289
settings = _.defaults({}, settings, _.templateSettings);
12881290

12891291
// Combine delimiters into one regular expression via alternation.
@@ -1327,7 +1329,6 @@
13271329
throw e;
13281330
}
13291331

1330-
if (data) return render(data, _);
13311332
var template = function(data) {
13321333
return render.call(this, data, _);
13331334
};

0 commit comments

Comments
 (0)