Today I was reading Trek’s tutorial for the fourth time, hoping that I would get it this time (don’t get me wrong, it is an awesome resource, but I am new to client side development in general and find that tutorial geared more toward experts). Anyway, I noticed this block of code:
<script type="text/x-handlebars" data-template-name="contributors">
{{#each person in controller}}
{{person.login}}
{{/each}}
</script>
It seems obvious that here we iterate trough items in controller and refer to them as person inside each iteration. But where does the controller reference come from? Is this some special keyword that is defined by Ember and made available in the context of each view?
If controller is a special reference made available by Ember, I would like to know more about how it works. Can you point me to documentation or even Ember source where such keywords are defined so that I can learn what other references are available from inside a view and how do they work?
No, it’s not a special keyword, it’s just a property of the
viewwhich is set when using theconnectOutletmethod described below:If you read below your example, you see:
So the
connectOutletmethod:AllContributorsViewAllContributorsControlleras the view’s default rendering context (it means that thecontrollerproperty of the view is set toApp.router.allContributorsController, because the default view rendering context is its controller, or its parent view context when no controller is set, see the view context source code.{{outlet}}appearsAllContributorsControllerinstance (here[{login:'wycats'}, ...])I suggest you to read entirely the article and then try to do it yourself.
There are also a lot of Ember resource you could read, see this StackOverflow answer.