
Untitled
By: a guest on
Jun 20th, 2012 | syntax:
JavaScript | size: 0.67 KB | hits: 27 | expires: Never
Ember.Handlebars.registerHelper('short_price', function(property) {
console.log(this.getPath(property)); // <--- prints undefined
var value = this.getPath(property), short_price = parseFloat(value).toFixed(2);
// left pad with spaces so that numbers are aligned
// var short_price = _.str.lpad(String(short_price), 7, " ")
// ^ doesn't align. need fixed-width fonts but looks awful
return new Handlebars.SafeString(short_price);
});
// Template
{{#each item in controller}}
{{#view App.Item itemBinding="item"}}
<span>{{item.number}}</span>
<span class="numeric">{{short_price item.total}}</span>
{{/view}}
{{/each}}