Is it true the Ember won't render the same view/controller combo multiple times?

My understanding is that:

  • {{partial}} & {{view}} - use the parent controller
  • {{render}} - creates a new controller, but you can only use it once on the page
  • {{control}} - creates a new controller every time it’s used

I want to re-use the same controller over and over on one page, so I have a single source of truth for it’s content.

I’ve got a shopping cart view that I’m showing a few times on the page (once as an icon in the topbar, and once in navigation that comes in from the side of the screen) and that should obviously use the same controller since it’s the same data.

My workaround is to put the data in my ApplicationController, and add a ‘cart’ property that references it in every controller that I call {{render cartButton cart}} from.

Seems hacky. I’d rather just be able to call {{render cart}} over and over and have it re-use the controller. Is there a reason why we wouldn’t want to be able to do that?

Best, Erik

Components are probably a better solution than {{control}} in most cases. Control is still experimental and is hidden behind a flag. It may be changed significantly or even remove in the future. See Templates are HTML - Components - Ember Guides for more information about components.