handlebars.js

How to get an array value at index using Handlebars.js?

南笙酒味 提交于 2019-11-27 13:08:59
问题 Say I have JSON: { userinput: [ {name: "brian", "value": "i like pies"}, {name: "susan", "value": "memes are stupid"} ], feedback: [ {value: "i also like pies"}, {value: "null"} ] } And I'm trying to draw a table like this: name ..... | input ...... | feedback -----------|----------------|----------------- brian | I like pies | I also like pies susan | mems are stupid| null And while I recognise that it would be better to have feedback as a value of "userinput", what I have is not done like

Is it possible to load a Handlebars template via Ajax?

橙三吉。 提交于 2019-11-27 12:27:21
I would like to load additional templates on the fly. Is it possible? Mike Aski 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. I was just looking for the same thing and am about to have a play with the snippet below credit: borismus on github https://gist.github.com

How to format date in meteor template

走远了吗. 提交于 2019-11-27 11:47:53
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 David Weldon You may want to create a global helper like: Template.registerHelper('formatDate', function(date) { return moment(date).format('MM-DD-YYYY'); }); Then you can use it like: {{#each vname}} {{formatDate

Node.js with Handlebars.js on server and client

折月煮酒 提交于 2019-11-27 10:48:24
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 Backbone.js and want to use Handlebars for the views controlled via Backbone. The problem is that

Handlebars.js Else If

丶灬走出姿态 提交于 2019-11-27 10:10:48
I'm using Handlebars.js for client side view rendering. If Else works great but I've encountered a 3 way conditional that requires ELSE IF: This doesn't work: {{#if FriendStatus.IsFriend }} <div class="ui-state-default ui-corner-all" title=".ui-icon-mail-closed"><span class="ui-icon ui-icon-mail-closed"></span></div> {{else if FriendStatus.FriendRequested}} <div class="ui-state-default ui-corner-all" title=".ui-icon-check"><span class="ui-icon ui-icon-check"></span></div> {{else}} <div class="ui-state-default ui-corner-all" title=".ui-icon-plusthick"><span class="ui-icon ui-icon-plusthick"><

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

醉酒当歌 提交于 2019-11-27 10:09:35
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 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 the route determined by the router. Based on the route the corresponding controller and view are used. This

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

白昼怎懂夜的黑 提交于 2019-11-27 09:57:29
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 differences I am missing? frontendbeauty You've pretty much nailed it, however Mustache templates can also be

Handlebars.js: How to access parent index in nested each?

三世轮回 提交于 2019-11-27 09:45:10
问题 How to access parent @index value in each-loop? Tried the following: {{#each company}} {{#each employee}} {{../@index}} // how to access company index here? {{/each}} {{/each}} This results to an error: Expecting 'ID', got 'DATA' 回答1: There is a syntax error in the example. The correct syntax is {{@../index}} . We are looking at ways that we can support custom naming of these parameters in future versions of the language so this is easier to deal with. https://github.com/wycats/handlebars.js

Handlebars Template rendering template as text

佐手、 提交于 2019-11-27 07:44:35
I created a helper in Handlebars to help with logic, but my template parses the returned html as text rather than html. I have a quiz results page that is rendered after the quiz is completed: <script id="quiz-result" type="text/x-handlebars-template"> {{#each rounds}} {{round_end_result}} {{/each}} <div class="clear"></div> </script> For each of the rounds, I use a helper to determine which template to render a round's result: Handlebars.registerHelper("round_end_result", function() { if (this.correct) { var source = ''; if (this.guess == this.correct) { console.log("correct guess"); var

How to Pass an Object to client Javascript - NodeJS & express

好久不见. 提交于 2019-11-27 07:27:20
问题 I'm having a little bit problems, I'm trying to send an object to use on my Javascript client side, whenever I render the view. I am sending it this way (Im using Handlebars) > locations=[ { > local:"my_local", > desc:"myDesc" > }]; res.render('myView', { locaciones:locaciones }); // Then in my view Inside a script tag i try to get that var and print it <script> var myObj='{{locations}}'; console.log(locations); </script> the result is this : [object] and I can't use any property of it