You could define isAdmin
computed property in Application Controller:
// application controller
isAdmin: Ember.computed(function() {
// your logic here
})
// application template
{{#if isAdmin}}
{{admin-header}}
{{else}}
{{user-admin}}
{{/if}}
or you could wrap it as header-nav
component with isAdmin
property, so:
// application template
{{header-nav isAdmin=isAdmin}}
UPDATE
(Details with ember-simple-auth for @Grimmy)
1) Inject currentUser
into session
(for example, https://stackoverflow.com/a/30894082/4950029)
2) Resolve currentUser
in beforeModel
hook and set currentUser
controller property:
//route
beforeModel: function() {
var self = this;
this.session.get('currentUser').then(function(user) {
self.controllerFor( self.routeName ).set('currentUser', user);
},function() {
self.controllerFor( self.routeName ).set('currentUser', null);
});
}
//controller
isAdmin: Ember.computed('currentUser.role', function() {
return (this.get('currentUser.role') === 'admin');
}),
//template
{{#if isAdmin}}
{{admin-header}}
{{else}}
{{user-admin}}
{{/if}}
or as answered above
//controller
roleBasedComponentName: Ember.computed('currentUser.role', function() {
return ((this.get('currentUser.role') === 'admin') ? 'admin-header' : 'user-header');
})
//template
{{component roleBasedComponentName user=currentUser}}