handlebars.js

SetTimeout vs. Ember.run.later in an ember app?

南楼画角 提交于 2019-12-02 22:04:45
Inside my handlebars template: Today's date: {{currentDate}} Current Time: {{currentTime}} Inside my helpers: Ember.Handlebars.registerBoundHelper 'currentDate', (option) -> moment().format('LL'); Ember.Handlebars.registerBoundHelper 'currentTime', (option) -> moment().format('h:mm:ss a'); How would I go about updating the currentTime to the view every 1 second? I have read the Ember recommends Ember.run.later but I can't quite figure out where to put it and how to call it using this helper. Toran Billups You can use Ember.run.later like you would normally use setTimeout Ember.run.later(

Precompiling Handlebars.js templates in Windows

▼魔方 西西 提交于 2019-12-02 22:00:54
Looking at the Handlebars.js documentation for precompilation. The instructions are for OSX. Can this be done on Windows as well? If so, when they say to "install node and npm" does "node" refer to " node.js "? Install Node.js for Windows from here: http://nodejs.org/download/ . Run in the command prompt: npm install handlebars -g Now you can use the following syntax in the command prompt: handlebars <input> -f <output> ,where <input> is an original template file name, and <output> is a pre-compliled template file name. Example: handlebars person.hbr -f person.js In visual studio you have 2

Get DOM element using meteor template helpers

泪湿孤枕 提交于 2019-12-02 21:10:55
For example my html is <template name="atest"> <a href="{{route}}" data-test="test">Click</a> </template> In meteor template helpers, I want to be able to select the anchor tag. Template.atest.route = function() { console.log(this.data-test); }; I am not sure if this can be done or not, but certainly, it cannot be done via any method I have tried. I know there is a way to pass argument in a template instance, but I don't want that. I want to be able to select that anchor tag that template instance is in and do something with it. Appreciate any help I can get. Not in helpers, but in the

How can I precompile HandlebarsJS templates from Visual Studio?

假装没事ソ 提交于 2019-12-02 21:10:51
Is it possible to precompile Handlebars Templates from a postbuild event of Visual Studio or in the App_Start of a MVC web app? Thanks so much in advance. Dale amhed Sure, you have many options: You can install node.js for windows and npm, and configure a post-build event to the compilation ( example here from previous question ) If you're using ember.js, here's an implementation that uses bundle transformation to achieve precompilation. Another for ember.js that supports components, here's the implementation , that also uses bundle transformation. Here is an example of compilation on C# using

Using Handlebars templates with external JSON

安稳与你 提交于 2019-12-02 20:59:48
I feel really stupid, but I can't figure this out. I'm trying out Handlebars.js, but I can't get it to display data from the Twitter API. Here's what I've got: $.ajax({ url : 'http://twitter.com/statuses/user_timeline/alexlande.json', dataType : 'jsonp', success : function( tweets ) { var source = $('#tweet-template').html(); var template = Handlebars.compile(source); var context = tweets; $('#container').html(template(context)); } }); That doesn't display anything in my template, but the following code works as expected: var source = $('#tweet-template').html(); var template = Handlebars

How to wire a Backbone View to a meteor handlebars template?

空扰寡人 提交于 2019-12-02 20:59:01
Looks like Backbone.view, meteor and handlebars have overlap functionality when it comes to manipulating a section of the DOM. I looked at the ToDo app which is suppose to use Backbone, but in reality, they only use the Router. Backbone views also deal with templates... but they sound so different from meteor templates. Besides, it looks like both backbone & meteor can update the ui on a model update. ok, I am lost!? Who does what? Is Backbone really useful for a Meteor App? Can Backbone & Handle bars coexist? and if they can, in the Meteor context, how to wire a Backbone view to a handlebars

Calling Helper Within If Block in Handlebars Template

和自甴很熟 提交于 2019-12-02 20:13:55
I am working with Handlebars.js template engine and am trying to figure out a way to do something like this (contrived example): {{#if itemSelected "SomeItem"}} <div>This was selected</div> {{/if} where itemSelected is a registered helper like this: Handlebars.registerHelper("itemSelected", function(item) { var selected = false; // Lots of logic that determines if item is selected return selected; }); I get errors when trying to use this syntax for the template, and I cannot find any example showing this kind of thing. I do see simple #if blocks like this... {{#if myValueInContext}} <div>This

How do I lowercase a field using Handlebars.js?

余生长醉 提交于 2019-12-02 19:57:53
I want to do something like this: {{user.name.toLowerCase()}} but I get this error: Error: Parse error on line X: ...tatus {{user.name.toLowerCase()}}"> -----------------------^ Expecting 'ID', got 'undefined' Cyril N. As simply explained in the doc : Handlebars.registerHelper('toLowerCase', function(str) { return str.toLowerCase(); }); And just use it like this : <h1>By {{toLowerCase author}}</h1> If you're just trying to display some text as lowercased in HTML (regardless of whether or not it's generated by handlebars), you can use CSS and apply text-transform like so: .css-class-here { text

Accessing an instance of a controller or a view in ember

旧街凉风 提交于 2019-12-02 19:38:19
My understanding is that when I run App.CheeseController = Ember.Controller.extend({ type:"brie"}); A class CheeseController is created and that when I activate the Cheese route an instance of that class is made which is what I actually touch when talking to the controller in my handlebars template. Is it possible to directly access that instantiated object from within the javascript console (or from within my program)? More generally, where do the objects that Ember automatically makes live? Mike Grassotti A class CheeseController is created and that when I activate the Cheese route an

handlerbars.js check if list is empty

心已入冬 提交于 2019-12-02 18:56:10
Is there a way in Handlebars.js templating to check if the collection or list is null or empty, before going and iterating through the list/collection? // if list is empty do some rendering ... otherwise do the normal {{#list items}} {{/list}} {{#each items}} {{/each}} The "each" tag can take an "else" section too. So the simplest form is: {{#each items}} // render item {{else}} // render empty {{/each}} Duane If you have something that you want to display once and only if the array has data , use {{#if items.length}} //Render {{/if}} .length will return 0 for empty arrays so we have achieved