exAres
exAres

Reputation: 4926

How to use parent template's properties in child template in EmberJS?

I have a /newLicense route defined inside application route ('/') as :

App.Router.map(function() {
    this.route('newLicense', {path: '/newLicense'});
});

I have a property in application controller called is_admin which gets set properly every time the application controller is called. Now in newLicense template, I want to show a message based on whether logged in user is admin or not (which is stored in is_admin of application controller).

I tried

{{#if is_admin}}
    <p> You are logged in as Admin user. </p>
{{else}}
    <p> You are logged in as Read-Only user. </p>
{{/if}}

But it's not working. I also tried to provide application controller in newLicenseController as :

App.newLicenseController = Ember.ObjectController.extend({
    needs: ['application'],
});

But it's still not working. Then I tried {{#if application.is_admin}} still no luck.

Any help on this concept is much appreciated. Thanks.

Upvotes: 0

Views: 657

Answers (1)

exAres
exAres

Reputation: 4926

Got it. It was a simple mistake. One should access the properties of controllers listed in needs as : {{controllers.controller_name.property_name}}.

So in this case, it would become :

{{#if controllers.application.is_admin}}
    <p> You are logged in as Admin user. </p>
{{else}}
    <p> You are logged in as Read-Only user. </p>
{{/if}}

Upvotes: 1

Related Questions