Search code examples
javascriptmeteoriron-router

iron router: render template in named yield from event


can I somehow render a template in a specific yield from an event using iron router?

Template:

<template name="groupDetails">
    {{#with selectedGroup}}
        <h2>{{name}}</h2>
        {{> groupNav}}
        {{> yield 'groupOption'}}
    {{/with}}
</template>

Event action:

Template.groupNav.events({
  'click .groupStatisticsNavLink': function () {
    layout.render('stats', { to: 'groupOption' });
  }
});

I want to render a template called "stats" in a yield named "groupOption" from pressing a button.


Solution

  • Inside template helpers and events, you can just use a reference to Iron.controller(), which returns the current RouteController.

    var controller = Iron.controller();
    // you now have access to all controller properties and methods
    

    so your event would look like

    Template.groupNav.events({
      'click .groupStatisticsNavLink': function () {
        var controller = Iron.controller();
        controller.render('stats', { to: 'groupOption' });
      }
    });