How to render "post" {{outlet}} inside "posts" #each


What is the best way to render a “post” {{outlet}} inside a “posts” #each loop?

I can do:

{{#each untilOutlet as |post|}}
  List post
{{#each fromOutlet as |post|}}
  List post

and create “untilOutlet” and “fromOutlet” in the “posts” controller? Is this the best way?


Is there an example somewhere for me to look at?


How about:

{{#each posts as |post|}}
    List post
    {{#if (eq post selectedPost)}}
        {{post-detail-component model=post}}

eq is from ember-truth-helpers


Thanks. I will try. Is there a route for each selectedPost so you can bookmark it?


I am testing this on

How do I get selectedPost to respond to the id in the url?


There can be a route for each selectedPost. Put the template I provided in your post route.

You can share template code between your posts route and your post route by using a component.

// posts template

{{posts-list posts=model}} {{!-- pass model from posts route --}}

// post route

import Ember from "ember";

export default Ember.Route.extend({
    model: function(params) {
        return this.modelFor('posts').findBy('id', params.site_id);
    setupController(controller, model) {
        this._super(controller, model);
        controller.set('posts', this.modelFor('posts'));

// post template

{{posts-list posts=posts selectedPost=model}}
{{!-- pass posts from parent posts route using modelFor, selectedPost from model in post route --}}

// posts-list component template

{{#each posts as |post|}}
    List post
    {{#if (eq post selectedPost)}}
        {{post-detail model=post}}


I don’t understand 100% yet but will try it. Thanks


I added the post-list component

But it does not give me “Testing”.

Perhaps this DEPRECATION: You attempted to set 'posts' from '(generated post controller)', but object proxying is deprecated. Please use 'model.posts' instead. is the problem?

The component works on every route.


@Gaurav0 It seems selectedPost=model does not arrive in the component on a post route.


See my pull request and feel free to ask questions.


Merged your PR and it works. I understand what you did with the {{outlet}} in posts but why do we need setupController in the post route?


It sets the property ‘posts’ on the controller to be all the posts in the post route, so that the post route also can send posts to the posts-list component.



@abuiles is this the 101 way? It is difficult to get this as a beginner so perhaps it is something for your book.