From a8ecddb624977d9fa1923455a4f13d4aec098233 Mon Sep 17 00:00:00 2001 From: Anthony Cole Date: Sat, 15 Nov 2014 16:29:56 +1100 Subject: [PATCH] Update 2011-01-28-what-is-a-view.md Account for the new way underscores.js handles templates in version 1.7.0 (http://underscorejs.org/#changelog) --- _posts/2011-01-28-what-is-a-view.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/_posts/2011-01-28-what-is-a-view.md b/_posts/2011-01-28-what-is-a-view.md index 861d53d1..9bd34476 100644 --- a/_posts/2011-01-28-what-is-a-view.md +++ b/_posts/2011-01-28-what-is-a-view.md @@ -142,12 +142,14 @@ _Using template variables_ this.render(); }, render: function(){ - //Pass variables in using Underscore.js Template - var variables = { search_label: "My Search" }; - // Compile the template using underscore - var template = _.template( $("#search_template").html(), variables ); - // Load the compiled HTML into the Backbone "el" - this.$el.html( template ); + // Set an object containing our variable(s) + var variables = { search_label: "My Search"}; + // Reference the template partial using underscore + var template = _.template( $("#search_template").html() ); + // Pass variables into the Underscores.js template and compile it + var result = template(variables); + // Load the compiled HTML into the Backbone "el" + this.$el.html( result ); }, events: { "click input[type=button]": "doSearch"