1
votes

I've got an Ember Object defined which only holds some functions. I would like to access these functions in my templates but somehow it doesn't work. There is no error given nor any log statements.

App.AuthManager = Ember.Object.extend({
    isAuthenicated : function () { 
        return true;
    }
}).create();

Now in my template I would like to

{{#if App.AuthManager.isAuthenticated}}
    <ul>...</ul>
{{/if}}

The markup within the if statement is always printed, doesn't handlebars interpret the object function here?

1

1 Answers

4
votes

The guide on Handlebars Basic states that

Each template has an associated controller: this is where the template finds the properties that it displays.

That means the scope of the template is the controller and only the controller, you cannot access other objects in your application straight from a handlebars template.

I think that what you are trying to achieve can be done using the register and inject functions of the Ember.Application class.

Once the AuthManager object is injected in controllers, you should be able to access the property isAuthenticated within your template like so:

{{#if isAuthenticated }}
  <ul>....</ul>
{{/if}}

My source for this answer was from this website: http://madhatted.com/2013/5/26/communication-between-controllers-in-ember-js