Quick question on filtering (Solved)

I have a #privatenewsletter tag that I use for member-only newsletters. I then use that tag to keep them off the front page in the non-featured section, but still make them available elsewhere for members to read on the web site if they want to.

{{#get “posts” filter=“featured:false + tags:-[hash-privatenewsletter]” as |notfeatured|}}

So, I wanted to also filter them out of the archive page (same reasoning). The pertinent code in the archive page is

{{#foreach posts visibility="all" }}
    <article class="post post-date-{{date format="M"}}">
        <div class="post-label" style="font-size:18px; margin-top:10px; color:blue;"><b>{{date format="MMMM YYYY"}}</b></div>
        <a class="post-link" style="font-size:14px;" href="{{url}}"><b>{{title}}&nbsp;&nbsp;</b></a><i style="font-size:14px;">({{tags}})</i>
        <p style="font-size:12px; margin-left:14px;">{{excerpt}}</p>
    </article>
{{/foreach}}

I tried putting the same filter statement on the {{foreach}} line, but it didn’t work. I then tried adding a {get “posts” line with the filter. It worked, but broke the pagination.

If I can’t filter them out of the archives page, it’s not a huge deal – but, it would be better if I could. (I’m going to give them their own page.)

Thoughts?

Would you be able to share your routes.yaml so we can see your current setup?

It sounds to me like you want to use either channels or collections for your archive page, with a filter on, and then a separate collection for your #privatenewsletter posts.

Sure …

routes:
  /subscribe/: members/subscribe
  /signup/: members/signup
  /signin/: members/signin
  /account/: members/account
  /archive/:
    controller: channel
    template: archive

collections:
  /:
    permalink: /{slug}/
    template: home
    filter: tag:-hash-privatenewsletter

  /newsletter/:
    permalink: /{slug}/
    template: index
    filter: tag:hash-privatenewsletter

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

Hmm … I’ve never totally understood how routes.yaml works. I was able to modify it when I made a custom home page – but the filter that’s there doesn’t work. Stories tagged #privatenewsletter still show up, so I tried adding the filter in the home page code itself.

So, any thoughts on this setup? The home page is working, with the filter in the code. The archive page is working – until I try to filter out the newsletters.

Oh, and I got my newsletters.hbs file built, and changed routes.yaml to point to it. Works as it should – except now the sidebar is under the main content. Ugh.

Update: Changed routes.yaml as follows:

routes:
  /archive/:
    controller: channel
    template: archive
    filter: tag:-[hash-privatenewsletter]

  /newsletters/:
    controller: channel
    template: newsletter
    filter: tag:[hash-privatenewsletter]

collections:
  /:
    permalink: /{slug}/
    template: home
    filter: tag:-hash-privatenewsletter
 
taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

Still have two problems:
Archive page is including the newsletters, even though the filter in routes.yaml should prevent that.
Newsletter page has the sidebar below the list of newsletters. It’s a direct copy of the archive page, which is working correctly.

Thanks for pointing me in the direction of modifying routes.yaml file. Any further ideas welcome.

Any suggestions on fixing the problem on the archive page?

On your archive page, are you using a #get helper? Can you share the template?

Sure.


{{!< default}}

<div class="container">
  <div><h3 style="color:blue;">Archive of All Posts</h3><i>{{pagination.total}} posts, organized by month.<br/>You can also view posts in <a onmouseover="this.style.textDecoration = 'underline'" onmouseout="this.style.textDecoration = 'none'" href="https://forwardky.com/tags/">individual categories.</a></i><br/><hr style="border:solid 1px black; clear:both; display:block; width: 96%; color:black; height: 2px; margin-top:12px;"></div>
   
  <div class="content">
    <div class="archive js-post-feed">
      {{#foreach posts visibility="all"}}
        <article class="post post-date-{{date format="M"}}">
          <div class="post-label" style="font-size:18px; margin-top:10px; color:blue;"><b>{{date format="MMMM YYYY"}}</b></div>
          <a class="post-link" style="font-size:14px;" href="{{url}}"><b>{{title}}&nbsp;&nbsp;</b></a><i style="font-size:14px;">({{tags}})</i>
          <p style="font-size:12px; margin-left:14px;">{{excerpt}}</p>
        </article>
      {{/foreach}}
    </div>
    <br/>

    {{pagination}}
  </div>
</div>

Any insights into that routes.yaml file? Or on the archive page code?

One more try – any ideas?

I tested your routes.yaml file but I couldn’t recreate the problem :thinking:. Filters worked as expected and archive, newsletter, and home page rendered with the right posts. Have you tried restarting Ghost?

I asked an earlier question about filtering. Thanks to the people who replied! As a reminder, the goal was to keep our #privatenewsletter posts from appearing on either the home page or the archives page, and only on the Newsletters page.

After making changes to routes.yaml, I got the #privatenewsletter posts off the front page, off the Archives page, and showing up only on the Newsletters page. BUT – the URL for each article on that page is some sort of GUID-like URL, like this:

Any idea what is causing this?

An update: I have tried various combinations of routes.yaml configurations, and none are working. I did learn from an earlier posting that if a post isn’t assigned a route, Ghose uses the preview URL. which is apparently what is happening to me.

Here’s the current ROUTES.YAML file. Note that with this file in place, I hit two of the three goals: no private newsletters on the home page, and no private newsletters on the Archives page.

routes:
/archive/:
  controller: channel
  template: archive
  filter: tag:-[hash-privatenewsletter]

/newsletters/:
  controller: channel
  template: newsletter
  permalink: /{slug}/
  filter: tag:[hash-privatenewsletter]

collections:
/:
  permalink: /{slug}/
  template: home
  filter: tag:-hash-privatenewsletter
 
taxonomies:
tag: /tag/{slug}/
author: /author/{slug}/

But, the Newsletters page still shows the funky URLs.

Thoughts?

(Please don’t open multiple topics about the same thing - makes it hard to keep track of discussions - I’ve merged the other thread into this one)

All posts must exist in a collection in order to have a slug. Currently newsletters don’t exist in any collection, so they don’t have one. It sounds like what you’re trying to accomplish would look like something along the lines of:

routes:
  /:
    controller: channel
    template: home
    filter: tag:-hash-privatenewsletter

collections:
  /archive/:
    template: archive
    permalink: /{slug}/
    filter: tag:-[hash-privatenewsletter]

  /newsletters/:
    template: newsletter
    permalink: /{slug}/
    filter: tag:[hash-privatenewsletter]

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/
2 Likes

Excellent! Does just what I wanted. Thank you!

I read all the documentation on Routes.YAML that I could find, and nowhere do I remember reading “All posts must exist in a collection in order to have a slug.” That was breaking news to me. Thank you for sharing that; it makes the distinction between routes and collections a little clearer. Thanks again!