underscore.js-templating

combine html template files into one JS file

China☆狼群 提交于 2019-12-01 16:43:28
I have HTML template files (underscore template syntax) These files are saved in HTML format so they would be easy to edit (IDE syntax highlight) I don't want to fetch them with ajax, but rather combine them all and include them as a js file. Using GULP as my task-runner, I would like it to somehow combine all the HTML to something like this, as a javascript file that I could include in my BUILD process: template_file_name is the HTML file name. var templates = { template_file_name : '...template HTML string...', template_file_name2 : '...template HTML string...', template_file_name3 : '..

Underscore rendering [object HTMLDivElement]

南楼画角 提交于 2019-12-01 14:34:36
I have an underscore template that is appending the following text " [object HTMLDivElement] " , but it's supposed to append value that "model.get('title')" returns. Here's my template: <script type="text/template" id="todoTemplate"> <div class='todoBlock'> <li class='appendedTodo'> <%= title %> </li> <button class='delete'>Delete</button><p> </div> </script> Here's my function: addTodoLi: function(model){ var todoData = model.get('title'); var compileTemplate = _.template( $('#todoTemplate').html() ); $('#todo-list').append( compileTemplate(todoData) ); }, Your todoData is (presumably) a

Boolean checks in underscore templates

霸气de小男生 提交于 2019-11-28 07:53:43
I had to replace the default underscore teplating delimiters/Interpolate regex for compatibility with asp.net webforms.From the website i opted for mustache like syntax _.templateSettings = { interpolate : /\{\{(.+?)\}\}/g }; tried this _.template("{{if(loggedIn)Welcome {{name}}}}",{name:"James",completed:true}); but seems this is not the way( since a error occurred) to check boolean expression using a templating system. But from the docs seems it is possible as well as execute arbitrary JavaScript code, with <% … %> So how do i execute arbitrary js code with the above mentioned interpolation

Boolean checks in underscore templates

百般思念 提交于 2019-11-27 02:01:07
问题 I had to replace the default underscore teplating delimiters/Interpolate regex for compatibility with asp.net webforms.From the website i opted for mustache like syntax _.templateSettings = { interpolate : /\{\{(.+?)\}\}/g }; tried this _.template("{{if(loggedIn)Welcome {{name}}}}",{name:"James",completed:true}); but seems this is not the way( since a error occurred) to check boolean expression using a templating system. But from the docs seems it is possible as well as execute arbitrary

templateSettings not working

妖精的绣舞 提交于 2019-11-26 23:17:41
问题 I get a compilation error at runtime when I attempt to render the following template: <script id="tmpl-books" type="text/template"> <% _.each(items, function(item) { %> <ul> <li>Title: <%= item.title %></li> <li>Author: <%= item.author %></li> </ul> <% }); %> </script> <script type="text/javascript"> _.templateSettings = { evaluate: /\{\{=(.+?)\}\}/g, interpolate: /\{\{(.+?)\}\}/g, escape: /\{\{-(.+?)\}\}/g }; var list = { items: [ { "title": "Myst: The Book of Atrus", "author": "Rand Miller"

Backbone template method. Why are we passing in a model?

試著忘記壹切 提交于 2019-11-26 11:39:49
问题 I can\'t figure out why we are passing in a model.toJSON() into this template: app.TodoView = Backbone.View.extend({ tagName: \'li\', template: _.template($(\'#item-template\').html()), render: function(){ this.$el.html(this.template(this.model.toJSON())); return this; // enable chained calls } }); The example comes from this tutorial. this.template(this.model.toJSON()) is the confusing part to me. The template method doesn\'t seem to take in an argument right? What is going on? 回答1:

Underscore template throwing variable not defined error

谁说胖子不能爱 提交于 2019-11-25 22:44:16
问题 I\'ve watched some videos on the topic of backbone js. This is an example straight from the video. It is from 2012, so I\'m thinking backbone rules/library have changed, but I can\'t figure out why this does not work at the moment. In the video, the person shows it running in the JS Fiddle, but I can\'t get it to work. (I\'ve included the necessary libraries in JS Fiddle, i.e. underscore, backbone and jQuery) var V = Backbone.View.extend({ el:\'body\', render: function () { var data = { lat: