FAQ Database Discussion Community


Passing data to view template is undefined in Backbone.js?

javascript,backbone.js,underscore.js-templating
All, I am trying to pass a simple JSON object for the time being (tried with a model but still the same problem). I have initialised my View as such with a variable called "skills" which I want to pass into my template. However inside the template it is saying...

Uncaught SyntaxError: Unexpected token ')' in underscore when looping throught template

javascript,underscore.js,underscore.js-templating
I have a problem when using underscore in Backbone application. In console I have Uncaught SyntaxError: Unexpected token ')' And it referer me to the underscore library : underscore.js:line 1443 What I whant to do is select template by id var UserList = Backbone.View.extend({ el: '.page', render: function(){ var self...

Underscore templates with Backbone

javascript,backbone.js,underscore.js,underscore.js-templating
I'm completely new in backbone framework. I have a model itemsOnSaleModel that contains an array of items and a View itemListView that render these items. The problem is that I can't figure out how to write the template correctly. Usually in this case I would have written something like this:...

Underscore template can't access model data

backbone.js,underscore.js,underscore.js-templating
I am trying to render a collection of views from a template, but I can't access my model data in the view template. If I place a <% debugger %> call in the template, I can see the patient variable in local scope as an object, and can also access...

How to partially substitute an Underscore.js template, or how to create a template from a template

javascript,templates,underscore.js,underscore.js-templating
I would create a master template for generating other templates. The only method I found is this one: var test_tpl_master = _.template( "StackOverflow <%= type %> question number <%= num %>" ); var test_tpl_1 = _.template(test_tpl_master({ "type": "good", "num": "<%= num %>" })); var test_tpl_2 = _.template(test_tpl_master({ "type": "stupid", "num":...

Underscore template returns nothing: why?

underscore.js-templating
This template has a spelling error in the first if statement, and it returns nothing. When I place a debugger statement in this template, it gets to the first if statement, then dies. Examining __p shows me valid javascript, so I'm confused on why the whole templating function is returning...

Event binding on underscore/lodash templates

javascript,jquery,lodash,underscore.js-templating
I have an example lodash template inside a jquery plugin as shown below: <div> <% _.forEach(circle, function(circle, idx){%> <a class='circle'> <%- circle.circleName %> </a> <%})%> </div> I would like to add click event handler to the a tag. Currently, I am doing the below after rendering the above template on...

Javascript templates using underscore.js

javascript,jquery,underscore.js,underscore.js-templating
I have a phones array that contains data from json: var phones = [ { "age": 0, "id": "motorola-xoom-with-wi-fi", "imageUrl": "img/phones/motorola-xoom-with-wi-fi.0.jpg", "name": "Motorola XOOM\u2122 with Wi-Fi", "snippet": "The Next, Next Generation\r\n\r\nExperience the future with Motorola XOOM with Wi-Fi, the world's first tablet powered by Android 3.0 (Honeycomb).", "price": 150 },...

Underscore.js template IE9 / IE10 not returning right code

javascript,internet-explorer,underscore.js,template-engine,underscore.js-templating
I have this code in my js file var selectedTagElement = _.template('$("#selected_tag_item_template").html()', item = { tag: label, value: value }); $('#wrapper_id').append(selectedTagElement); and this in my html file <script type="text/template" id="selected_tag_item_template"> <div class="tag_item selected js-selected_tag_item" data-tag-value="<%= item.value %>" data-tag-label="<%= item.tag %>"><%= item.tag %> </div> </script> Everything is working fine in all...

Underscore template not rendering variable with <%-

templates,escaping,underscore.js,underscore.js-templating
I have a simple template: <div class='welcome'>Welcome <%- first_name %>!</div> However my variable first_name is not rendered. This works fine: <div class='welcome'>Welcome <%= first_name %>!</div> and this correctly logs the variable: <div class='welcome'>Welcome <%- first_name %><% console.log(first_name);console.log(typeof(first_name)); %>!</div> which is of type string as expected. I couldn't find anyone with...