Positional index in Ember.js collections iteration

It’s old question but still gets a lot of hits. In the current version of Ember.JS one can use _view.contentIndex to display current index inside the loop. {{#each}} Index: {{_view.contentIndex}} {{/each}} If you need an adjusted index (for instance starting from 1) then there is a possibility of creating reusable helper increment Ember.Handlebars.registerBoundHelper(‘increment’, function(integer) { … Read more

Handlebars.js if block helper ==

The easiest thing would be to add a custom if_eq helper: Handlebars.registerHelper(‘if_eq’, function(a, b, opts) { if(a == b) // Or === depending on your needs return opts.fn(this); else return opts.inverse(this); }); and then adjust your template: {{#if_eq this “some message”}} … {{else}} … {{/if_eq}} Demo: http://jsfiddle.net/ambiguous/d4adQ/ If your errors entries weren’t simple strings then … Read more

Rendering resolved promise value in Ember handlebars template

You could have the property lazily set itself, something like: App.TopicItem = DS.Model.extend({ topic: DS.belongsTo(‘topic’), paddedPosition: function(key, value) { if (arguments.length > 1) { // > 1 args = this is a `set` return value; } else { // otherwise this is a `get` var _this = this; value = null; this.get(‘topic.course.lessons’). then(function(lessons) { // … Read more

Is it possible to load a Handlebars template via Ajax?

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.

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

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 is useful when rendering contents based on the route, which is the most common … Read more

Handlebars.js Else If

Handlebars supports {{else if}} blocks as of 3.0.0. Handlebars v3.0.0 or greater: {{#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”></span></div> {{/if}} Prior to Handlebars v3.0.0, however, you will have to either define a helper that handles the branching logic … Read more

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

You’ve pretty much nailed it, however Mustache templates can also be compiled. Mustache is missing helpers and the more advanced blocks because it strives to be logicless. Handlebars’ custom helpers can be very useful, but often end up introducing logic into your templates. Mustache has many different compilers (JavaScript, Ruby, Python, C, etc.). Handlebars began … Read more

Using Express Handlebars and Angular JS

Your first solution is possible, AngularJS allow to change the start/end symbols of text interpolation like this: appModule.config(function($interpolateProvider) { $interpolateProvider.startSymbol(‘{[{‘); $interpolateProvider.endSymbol(‘}]}’); }); Then you could use it in your template: <div>{[{message}]}</div> Also see: $interpolateProvider documentation Hope this helps.