Filters for channel and collection are not applied

Hi Everyone, could someone explain to me why my filters are not applying correctly?
I have a collection for “blog” and a channel “release-notes”:

routes:
   ...
  /release-notes/:
    controller: channel
    filter: tag:release-notes
    template: blog-index


collections:
  /blog/:
    permalink: /blog/{slug}/
    template: blog-index
    filter: tag:blog
    data: tag.blog

in the blog-index template I do:

    {{#get "posts" filter="featured:false" include="authors" order="published_at desc"}}
      {{#foreach posts columns="3"}}

        {{#if @rowStart}}<div class="row">{{/if}}
          {{> third-post-card}}
        {{#if @rowEnd}}</div>{{/if}}

      {{/foreach}}
    {{/get}}

I am guessing that since I get all posts here again, that causes my filters not to apply.
How is this done correctly?

Many thanks in advance.

Because your routes already define the data for your blog-index page, you can omit the {{#get}} helper and loop through the posts directly with {{#foreach posts}}. If you want to filter on featured posts, you can either add that filter to your routes file or use the {{#if}} helper within the loop.

filter: tag:blog+featured:false
{{#foreach posts}}
  {{^if featured}}
  ...
  {{/if}}
{{/foreach}}

Let me know if that works!

Thanks for the reply @TheRoyalFig.
This works for the featured posts but now I end up with gaps in my columns where a featured post is not redered.
Do you have another idea?
Here is my code for reference

    <div class="row">
      <div class="col-12">
          {{#foreach posts}}
            {{#if featured}}
              {{> row-post-card}}
            {{/if}}
          {{/foreach}}
        </div>
      </div>
      {{#foreach posts columns="3"}}

          {{#if @rowStart}}<div class="row">{{/if}}
            {{^if featured}}
              {{> third-post-card}}
            {{/if}}
          {{#if @rowEnd}}</div>{{/if}}

      {{/foreach}}

      </div>
    </div>

My first thought is to scrap the custom route and use the {{#get}} helper to fetch the posts you need.

But to offer more guidance, I think I’d need to see what you’re trying to accomplish. Can you share a link or screenshot?

I have the blog online here: Blog - Query.me
I am trying to make a channel with blog posts that are tagged ‘release-notes’.

OK!

Do you want the release note posts to show up on /blog, too? Or only on /release-notes/?

And what are you using the row attribute to do? Is it for styling purposes?

Yes, in block I would want everything shown that is tagged as “blog”.
My release-notes are tagges as “blog” and as “release-notes”.
The row class is part of bootstraps grid layout: Grid system · Bootstrap

To create the channel, there’s a couple of different ways to do it.

The easiest is to link to /tag/release-notes. Ghost will automatically create a tag archive there of all your release notes posts.

If you want to create a custom channel, then I’d use a custom route with a channel controller. You’d want to add the following to your routes.yaml file in Settings > Labs > Routes.

routes:
  /release-notes/:
    controller: channel
    filter: tag:release-notes

Hey so, thanks for your help but that is actually how I had it to begin with if you check my initial post.
The problem is that the filter does not work when I want to seperate featured posts from the rest of them to display them on top.
I think in the end I will just make two seperate templates: one for all blog posts and one for release-notes only. They will be identical with only the small difference of using a different filter in the #get.

Sorry, too, I think I got lost on the thread!

Here’s one other technique you can try.

In your routes.yaml file, you can actually return the posts so that featured posts are first, followed by the rest. In your case, that would look like this:

routes:
  /release-notes/:
    controller: channel
    filter: tag:release-notes
    order: featured desc, published_at desc

This will load release-notes posts by featured first, then the rest. Let me know if that works!

1 Like

Cool yeah this actualy works! Thanks a lot!