Reputation: 1371
I am creating an application with complex layout recently, so I'm trying to find an elegant way to use lots of template and make them work as I wish to.
For a start, I have some UI components to fit in, these components has no relation with models and no need to use routes to manage states, so I use {{render}}
helper to do something like:
<script type="text/x-handlebars">
<div class="wrapper">
{{render component_1}}
{{render component_2}}
<div class="main">
{{outlet}}
</div>
</div>
</script>
This way works, but honestly I don't know anything about renderTemplate
method before I've done this. After few days, I try this instead:
<script type="text/x-handlebars">
<div class="wrapper">
{{outlet component_1}}
{{outlet component_2}}
<div class="main">
{{outlet main}}
</div>
</div>
</script>
and add extra codes in route:
MyApp.ApplicationRoute = Ember.Route.extend({
renderTemplate: function() {
this.render();
this.render('component_1', {
outlet: 'component_1',
into: 'application'
});
this.render('component_2', {
outlet: 'component_2',
into: 'application'
});
}
});
then I got same results.
Now, I'm struggling to make a choice between these two methods. I prefer to first one because I think these UI components will never use routes since they don't have any states, so it's not necessary to write extra codes in ApplicationRoute
. But there're two concerns still:
{{render}}
.So I need some explanations and suggestions in order to use {{render}}
and renderTemplate
wisely, thanks for any helps.
Upvotes: 3
Views: 1329
Reputation: 145
If they are components, and not full-fledged routes, just use render in your template.
{{render}} uses the same named controller and template in the current context. So that would mean it grabs the context from the current route. If a view class with the same name exists, it uses that view class. If a model is specified, it becomes the model for that controller. Default target will be that same controller.
Upvotes: 1