2
votes

The case is I want my {{render}} to infer a controller name from supplied ember-data model's name automatically.

e.g. in {{render 'animal' animal}}, if animal is a Cat, I hope the template is rendered with a CatController

It seems that the render helper accepts a controller= parameter now, but then regards the parameter as a literal instead of a variable.

https://github.com/emberjs/ember.js/blob/master/packages/ember-routing-handlebars/lib/helpers/render.js#L115

For now, I just put the representation codes (needed by template) in target models, which I believe is bad.

What is the right way to implement this polymorphic-alike rendering?

2

2 Answers

0
votes

The functionality you are describing is exactly what ember does, as described here http://emberjs.com/guides/templates/rendering-with-helpers

{{render 'animal' animal}}

will render the animal template, with the Animal model, AnimalController controller and AnimalView view, if they exist.

0
votes

You need to use an alternative to the render helper, where you can specify everything you need.

this.render('TEMPLATENAME', {
    into: 'TEMPLATE/LAYOUT',
    outlet: 'OUTLET NAME IN TEMPLATE',
    controller : 'CONTROLLER NAME FOR CURRENT TEMPLATE',  /*  optional  */
    model : 'MODEL NAME FOR CURRENT TEMPLATE',   /* optional  */ 
});

You can add it directly from your route in the renderTemplate function

App.ApplicationRoute = Ember.Route.extend({
    model: function(params){ },
    renderTemplate: function(){

        this._super();   /* Add it to prevent weird behaviour */

        this.render('header', {
           into: 'application',
           outlet: 'header',
           controller: 'headerMenu',
        )};

    },

});