Using #get breaks collections in routes.yaml?

i had collections set up so that posts with a particular primary-tag appeared on one page and posts with that tag (or any tag) appeared on the home page. In order to get posts marked “featured” to appear at the top of their collections, I changed index.hbs from

<main id="site-main" class="site-main outer">
    <div class="inner posts">

        <div class="post-feed">
            {{#foreach posts}}

                {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
                {{> "post-card"}}

            {{/foreach}}
        </div>

    </div>
</main>

to

<main id="site-main" class="site-main outer">
    <div class="inner posts">

        <div class="post-feed">
            {{#get "posts" filter="featured:true" limit="all" as |features paged|}}
                {{#foreach features}}

                {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
                {{> "post-card"}}

                {{/foreach}}
            {{/get}}
            {{#get "posts" filter="featured:false" limit="all" as |notfeatures paged|}}
                {{#foreach notfeatures}}

                {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
                {{> "post-card"}}

                {{/foreach}}
            {{/get}}
        </div>

    </div>
</main>

That worked, in that the featured posts appeared first, but it broke the collections. All posts for home and dickson appeared on both pages. Somehow this change screwed up routes.yaml.

Any ideas?

You’re never using the post data that is provided as part of the index route ({{#foreach posts}}). The {{#get}} helper is used to fetch additional data (posts, pages, tags, authors).

If you’re looking to have a static list of featured posts, the first {{#get}} block is correct, and the second {{#get}} block should be replaced with {{#foreach posts}}, and optionally {{^if featured}} to exclude featured posts in the current route.

You might also want to update your routing filter to exclude featured posts so the number of posts per page doesn’t change. (if featured posts are filtered in your loop, the posts per page on that specific page is reduced)

Like so:

    <div class="post-feed">
            {{#get "posts" filter="featured:true" limit="all" as |features paged|}}
                {{#foreach features}}

                {{> "post-card"}}

                {{/foreach}}
            {{/get}}
            {{#foreach posts}}
                {{^if featured}}
                    {{!-- The tag below includes the markup for each post - partials/post-card.hbs --}}
                    {{> "post-card"}}
                {{/if}}

            {{/foreach}}
        </div>

Do you mean that my routing filter constructs the “posts” value? So, if I exclude “featured” in the routing, the “posts” collection will have the correct number of non-featured posts, and I won’t need the {{^if featured}} exclusion in index.hbs?

I’m confused about the significance of your “posts per page” comment.

Yes. Posts per page is just an aesthetic thing, so it’s not a huge deal.

One thing to note is if you filter featured posts in your routes, you will have to create an additional route so the filtered/excluded posts will have a url.