This addon provides a template helper for presenting your data in your templates. See usage.
Of course, this could also be accomplished with a component but presenters offer a few advantages in some cases:
- Component names are required to contain a hyphen. Presenter names are not.
- Unlike components, when you use a presenter, it is immediately obvious that no extra DOM elements are introduced
- With a component, you are forced to write a template that often only contains
{{yield data}}
.
ember install ember-presenters
presenterName
: The name of the presenter, e.g. 'post' or 'dashboard/news-item'. Must be a string.key1=value1 ... keyN=value
: Properties that will be passed to the presenter. They are optional.
// app/presenters/comment.js
import Ember from 'ember';
import moment from 'moment';
export default Ember.Object.extend({
isRecent: Ember.computed('comment.createdAt', function() {
let createdAt = moment(this.get('comment.createdAt'));
return createdAt.add(7, 'days').isAfter();
})
})