Ember Templates
18 Oct 2015Ember Templates
- Decoupling the UI from the Backend data
- Handlebars Template Library
- http://handlebarsjs.com/
Definiting Template
ember generate template welcome
outlet helper tells the router to render the next appropriate template in place of outlet
Handlebar Conditionals
- Promote business logic inside template
- Promotes Separation of Concern (SoC)
If, else, and unless
app/template/showUser.hbs
Displaying List of Items
Binding HTML Tag Attributes
Building Custom Handlebar Helpers
Handlebar helpers provides reusable template to do most common tasks.
Helpers in the Ember CLI go inside
app/helpers
import Ember from 'ember';
export function currentDateTime(value, options) {
var dateString = "";
if (options.hash.format != undefined) {
dateString = moment().format(options.hash.format);
} else {
dateString = moment().format("MMM Do YY");
}
console.log("Current DateTime : " + dateString);
return dateString;
}
export default Ember.Helper.helper(currentDateTime);
template.hbs