Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does render template render the custom templates into the outlets defined in the default template used by a route.

I have a scenario in which in a specific route i have two outlets and in the same route i want to show two different templates in two different outlets.

Details template:

 <script type="text/x-handlebars" data-template-name="details">
    Details Template
    {{#linkTo "index"}}Home{{/linkTo}}
    <hr/>
    <h4>DETAILS</h4>
    <hr/>
    <div class='outletArea'>
    {{outlet "detailsList"}}
    </div>
    <hr/>
    <div class='outletArea'>
    {{outlet "detailsMatrix"}}
    </div>
</script>    

Route is defined as:

App.DetailsRoute = Ember.Route.extend({
renderTemplate: function () {
    this._super();//to render the details temlate whch has outlets
    this.render('detailsList', { outlet: 'detailsList' });//render the list in list outlet
    this.render('detailsMatrix', { outlet: 'detailsMatrix' });//rendet the matrix in matrix outlet
    }
});

But those two template are not getting rendered in those two outlets rather they get rendered in the root element directely.

Fiddle for my proble is http://jsfiddle.net/anshulguleria/eCTtu/

As in jsfiddle i wanted these two temlates to get rendered in the grey areas. Thus when going through the link my rendered templates are not removed and rendered again and again.

like image 496
guleria Avatar asked Jan 30 '13 06:01

guleria


People also ask

What does rendering a template mean?

Rendering a template is indeed always about producing content, but for a slightly wider description of content. It could be a chunk of html, for example an ajax call to get new items might produce some html describing the new items, but it doesn't have to be.

What is {{ outlet }} in Ember JS?

Here is the explanation: {{outlet}} -> This will provide a stub/hook/point into which you can render Components(Controller + View). One would use this with the render method of routes. In your case you will likely have a details route which could look like this.


1 Answers

Your details route is at the top level, so when calling render in its renderTemplate function without specifying the into option, it tries to find these outlets in the top level template (i.e. in the application template). You can see it in this JSFiddle.

If you were in a nested route, it search them in the parent template (AFAIK).

Consequently, you just have to add the into option like this:

this.render('detailsList', { outlet: 'detailsList', into: 'details' });
this.render('detailsMatrix', { outlet: 'detailsMatrix', into: 'details' });

And it works!

EDIT

It looks like Ember expect to have an application template that has an {{outlet}}. It seems to be a bug in Ember, I think you can post an issue in github.

I've updated the link above to add an application template.

like image 50
louiscoquio Avatar answered Nov 04 '22 21:11

louiscoquio