Outlet or render best practice?


#1

Consider this router:

Yu.Router.map ->
  @resource 'encounters'
  @resource 'user', { path: '/users/:user_id' }, ->
    @resource 'detailinfo'
    @resource 'friends'

In user template, except main outlet I also want to put in avatar. I can do this just using render ‘avatar’ avatar. But since there also edit action in avatar controller, I think use outlet is also acceptable.

Because:

  1. We can omit isEditing flag in edit controller.
  2. Other controller(for example edit controller) can use needs to get avatar controller(as I know we can not use needs if use render, am I right?)
  3. It seems that named outlet is born for this situation, right?

#2

I’d use render still. Is the edit avatar going to navigate away from other routes? or will you be able to edit it in place? If you are going to edit it in place render.

render you get to define the model to use, so you could tell it to use the current controller (whatever it might be at the current context of the code) and it could have a needs etc.


#3

Thanks for your reply! In fact I am also prefer render at first, perhaps because I from rails. But after some practice, I found a disadvantage of ember render: for example if I render 'basicinfo' basicinfo and inside basicinfo hbs template I also want to render ‘basicinfo/form_edit’ basicinfo. In this situation I need basicinfo controller attribute, such as isEditing. I can not use needs: ‘basicinfo’.w() since basicinfo controller is not a singleton controller(Documentation / “needs” API: is it only for singleton controllers?). At last I got two choice: use outlet to plugin basicinfo controller or use view to insrt basicinfo/form_edit.