Inherit output patterns from a super controller using an iron router

I have a supercontroller: ApplicationControllerthat outputs to my regions: header / footer. When one of my configured routes tries to give way to another region on a different template, the parent yieldTemplates controller is overridden.

Example:

   ApplicationController = RouteController.extend({
    yieldTemplates: {
        'footer': { to: 'footer' },
        'header': {to: 'header'}
    }
});

var SignUpController = ApplicationController.extend({
    template: 'signUp'

});

Router.map(function () {


    this.route('signup', {
        path: '/sign-up',
        controller: SignUpController,
        template: 'signUp-form',
        disableProgress: true,
        yieldTemplates: {
            'personal-signup': {to: 'signup-detail'}
        }
    });
});

Any idea why inheritance doesn't work in this situation?

+3
source share
2 answers

I had a similar problem, read the answer here: https://github.com/EventedMind/iron-router/issues/249#issuecomment-27177558

, RouteController. -.

, , :

var mainYieldTemplates = {
    'footer': { to: 'footer' },
    'header': {to: 'header'}
};

ApplicationController = RouteController.extend({
    yieldTemplates: mainYieldTemplates
});

var SignUpController = ApplicationController.extend({
    template: 'signUp',
    yieldTemplates: _.extend({}, mainYieldTemplates, {
            'personal-signup': {to: 'signup-detail'}
        }
    )
});

Router.map(function () {
    this.route('signup', {
        path: '/sign-up',
        controller: SignUpController,
        template: 'signUp-form',
        disableProgress: true,
    });
});

, "template" "signUp" , "signUp-form". "" . , .

+3

, monkeypatching RouteController, , . .

(function(){
  var orig = RouteController.extend;
  RouteController.extend = function(newChild) {
    var extendedTemplates = {};
    if (!newChild.yieldTemplates) {
      newChild.yieldTemplates = {};
    }
    _.extend(extendedTemplates, this.prototype.yieldTemplates);
    _.extend(extendedTemplates, newChild.yieldTemplates);
    newChild.yieldTemplates = extendedTemplates;
    return orig.apply(this, arguments);
  }
})();

-, - RouteControllers. , , yieldTemplates .

+2

All Articles