handlebars.js

Rendering resolved promise value in Ember handlebars template

若如初见. 提交于 2019-11-26 16:16:29
问题 Is there a good way to render the result of a promise in a handlebars template? For example, I have the following model: App.TopicItem = DS.Model.extend({ topic: DS.belongsTo('topic'), paddedPosition: function() { return this.get('topic.course.lessons'). then(function(lessons) { return lessons.indexOf(topicItem); }). then(function(index){ var position = index; if (position < 0) { return; } position = position + 1; return (position < 10 ? $.rjust(position, 2, '0') : position.toString()); }); }

Positional index in Ember.js collections iteration

自作多情 提交于 2019-11-26 16:14:38
问题 Is there a way to get positional index during iteration in ember.js? {{#each itemsArray}} {{name}} {{/each}} I'm looking for a way to have something like: {{#each itemsArray}} {{name}} - {{index}}th place. {{/each}} Update: As per the comment by @ebryn the below code works without using a nested view for each item: <script type="text/x-handlebars"> {{#collection contentBinding="App.peopleController"}} Index {{contentIndex}}: {{content.name}} <br /> {{/collection}} </script>​ http://jsfiddle

Is it possible to load a Handlebars template via Ajax?

人盡茶涼 提交于 2019-11-26 16:00:32
问题 I would like to load additional templates on the fly. Is it possible? 回答1: You can register new templates in Ember.TEMPLATES . They will then be available to views. An excerpt from my code (jQuery Ajax handler): success: function(data) { $(data).filter('script[type="text/x-handlebars"]').each(function() { templateName = $(this).attr('data-template-name'); Ember.TEMPLATES[templateName] = Ember.Handlebars.compile($(this).html()); }); } That's it. 回答2: I was just looking for the same thing and

How to format date in meteor template

不问归期 提交于 2019-11-26 15:45:57
问题 I need to display a date from database in the format 'mm-dd-yyyy'. As its saved in ISO format in mongodb how can I convert it in the template ? Here is my code. Template.templatename.vname = function () { return Posts.find(); } And in template {{#each vname}} {{ date }} {{/each}} Now its getting displayed like Tue Feb 04 2014 00:00:00 GMT+0530 (IST) I need to show it as mm-dd-yyyy 回答1: You may want to create a global helper like: Template.registerHelper('formatDate', function(date) { return

The context of “this” in Meteor template event handlers (using Handlebars for templating)

回眸只為那壹抹淺笑 提交于 2019-11-26 15:23:50
问题 A quick question on the context of the event handlers for templates in Meteor (with Handlebars). In the section of Documentation on template instances (http://docs.meteor.com/#template_inst) it is mentioned that " Template instance objects are found as the value of this in the created, rendered, and destroyed template callbacks and as an argument to event handlers " In the Templates section (http://docs.meteor.com/#templates) it says " Finally, you can use an events declaration on a template

Node.js with Handlebars.js on server and client

人盡茶涼 提交于 2019-11-26 15:18:46
问题 I have an app in Node.js using Expressjs and Handlebars as the template engine. Expressjs uses layouts and then renders views. The layout (layout.hbs) looks like this: <!doctype html> <html lang="en"> <head> </head> <body> {{{body}}} </body> </html> The {{{body}}} is replaced server-side, within node.js when you access a route. For example: app.get('/', function(req, res){ res.render('index'}) }) Will replace the {{{body}}} tag with the contents of index.hbs. Now, on the client side I'm using

ember.js + handlebars: render vs outlet vs partial vs view vs control

烂漫一生 提交于 2019-11-26 15:03:55
问题 There are scattered explainations of each around, but I'm still not 100% clear on the differences & usage. Could someone give me a side-by-side comparison? {{outlet}} {{outlet NAME}} {{render}} {{partial}} {{view}} {{control}} Note: this post was very helpful with partial vs render 回答1: They are all template helpers with the following main characteristics as described in emberjs guides. (http://emberjs.com/guides/templates/rendering-with-helpers/) 1. {{outlet}} - Renders a template based on

What are the differences between Mustache.js and Handlebars.js?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 14:58:31
问题 Major differences I've seen are: Handlebars adds #if , #unless , #with , and #each Handlebars adds helpers Handlebars templates are compiled (Mustache can be too) Handlebars supports paths Allows use of {{this}} in blocks (which outputs the current item's string value) Handlebars.SafeString() (and maybe some other methods) Handlebars is 2 to 7 times faster Mustache supports inverted sections (i.e. if !x ... ) (Please correct me if I'm wrong with the above.) Are there any other major

How to iterate over array of objects in Handlebars?

余生颓废 提交于 2019-11-26 12:04:45
问题 This might seem a silly question but I can\'t seem to find the answer anywhere. I\'m hitting this Web API that returns an array of objects in JSON format: Handlebars docs shows the following example: <ul class=\"people_list\"> {{#each people}} <li>{{this}}</li> {{/each}} </ul> In the context of: { people: [ \"Yehuda Katz\", \"Alan Johnson\", \"Charles Jolley\" ] } In my case I don\'t have a name for the array, it\'s just the root object of the response. I\'ve tried using {{#each}} with no

Using Express Handlebars and Angular JS

萝らか妹 提交于 2019-11-26 11:59:29
问题 Background I am currently building a website that uses NodeJS for the server, Express Handlebars(Just Handlebars but server side) , and hopefully AngularJS for some client side stuff. The Problem AngularJS and Handlebars use the same syntax for templating {{foo}} This causes a problem where AngularJS code will be interpreted by Express Handlebars first, which will then throw an error because the data it is trying to pull only exists in Angular not Node. The Question Is there a way to get