Apply controller to template without a route in Meteor

148 Views Asked by At

If I have a template that does not have its own route, how can I apply a controller to it? I have a template called Cart that is embedded in another template called Products:

<template name="Products">
<div class="row">
    <div class="col-md-6 col-md-offset-6">
        {{> Cart}}
    </div>
</div>

I don't have any route like www.myapp.com/cart or anything. If I use something like:

Router.route(, {name: 'Cart', controller: 'cartController});

I will get an error. Can someone help? Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

As was probably pointed out to you by the console, you can't have a comma there in JS. It seem your thinking was, just not to pass a route to the route. To do that in JS you'd have to do Router.route(undefined, ...). But that's btw..

It seems to me from reading the iron-router guide that you can simply pass a template to the controller. That way they are hooked together too.

I copied the example in the guide and edited to fit your needs:

CartController = RouteController.extend({
  template: 'cart',
  action: function () {
    this.render();
  }
});