0

In my Meteor app, I have two yield blocks: one for my global navbar and the other for my main content:

<template name="layout">

  <div>
    {{> yield region='navRegion'}}
  </div>
  <div>
    {{> yield}}  
  </div>

 </template>

How can I add an Iron Router Controller into my routes so that I can pass data into my global navbar (since it doesn't have a route)? Is it possible to run the two controllers at the same time? Or do I have to rely on helpers for the global nav?

Stu Stein
  • 888
  • 7
  • 6

2 Answers2

0

Let's say the template that you were trying to render in the main {{> yield}} was named home. The following would work.

Router.configure({
  layoutTemplate: 'layout'
});

Router.map(function () {
  this.route('home', {
    path: '/',
    template: 'home',
    yieldTemplates: {
      'navRegion': {
        to: 'navRegion'
      }
    }
  });
});
AJ.
  • 1,248
  • 10
  • 27
  • Thanks @AJ., but how do I connect one controller to my global navRegion that will control the data there, and connect a separate one to my home template, and have them both operate at the same time? Is that possible? – Stu Stein Apr 03 '14 at 07:44
  • If I'm understanding your question correctly, the iron router docs on [Parameterized routes][1] should allow you to achieve what you are looking to do. "A standard pattern is a route per object in a collection. You can achieve this with a parameterized route" [1]: https://github.com/EventedMind/iron-router#parameterized-routes-and-data – AJ. Apr 03 '14 at 16:22
  • I guess what I'm trying to achieve is having a global controller to pass global data to my global navbar, and then route controllers that changes with the routes to pass route-specific data. So at any point, you would have one global controller and one route-specific controller working at the same time on the same layout. Does that clarify? – Stu Stein Apr 03 '14 at 19:36
0

Here's the answer from @cmather, which he answered on my other post: How do I activate an Iron Router route without changing the path?

There is a one-to-one between a route and a route controller. You'll only ever have one controller running at a time, based on the route you're on. If you want to set a global value from a controller, and it doesn't make sense to do it in the global data context, you can always set a session value. For example: Session.set('currentId', this.params._id) - @cmather

Community
  • 1
  • 1
Stu Stein
  • 888
  • 7
  • 6