Collection without pages that have a certain header-value

Is there a way (via frontmatter preferably) to create a collection excluding pages with a certain custom value in the page-header?

hide_teasers: true

I have some pages (blog-children) that i want to show up only in the rss-feed and not in teasers on the website. I can’t get it to work on my blog-index with pagination.

In the template i tried

{% set cleaned = page.collection() %}
{% for p in collection %}
    {% if p.header.hide_teasers %}
     {% set cleaned = cleaned.remove(p) %}
    {% endif %}    
{% endfor %}

and then looping through the teasers like

{% for child in cleaned %}
    {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
{% endfor %}

That skips the “hidden” pages but if the limit is 6 and there are 4 hidden pages it only shows 2 teasers of a total of about 20-30 pages.

blog.md frontmatter is set like this atm:

content:
    items:
        - '@self.children'
    limit: 6
    order:
        by: date
        dir: desc
    pagination: true
    url_taxonomy_filters: true

This page Page Collections | Grav Documentation says, “filter” is not possible with custom header-values. So, how can i achieve what i am looking for?

Any hints or ideas? Thanks in advance.

Maybe you could try something like this:

{% set collection = page.collection() %}
{% for child in collection %}
    {% if child.header.hide_teaser == false or child.header.hide_teaser is not defined %}
      {% include 'partials/blog-list-item.html.twig' with {'page':child, 'truncate':true} %}
    {% endif %}
{% endfor %}

Previously, in blueprint hide_teaser would be:

header.hide_teaser:
    type: toggle
    toggleable: true
    label: Hide Teaser
    highlight: 0
    default: 0
    options:
      1: PLUGIN_ADMIN.ENABLED
      0: PLUGIN_ADMIN.DISABLED
    validate:
      type: bool

Thanks a lot! Didn’t know i need to “define” the variable in the blueprint. I guess blog.yaml? Unfortunately it ends up in the same result.
The first page shows only 2 teasers instead of 6.
Let me explain. I have about 30 children of /blog

  1. show teaser
  2. hide
  3. hide
  4. hide
  5. hide
  6. show
  7. show
  8. show
  9. show
  10. show
  11. show
  12. show
  13. show
  14. show
  15. show
  16. hide

what i get on page 1 with limit 6 is:
1.
6.

instead of
1.
6.
7.
8.
9.
10.

Do you understand?

@assbach, Instead of removing one or more items from a collection, you could also create a collection that only contains the items you are aiming at.

  • Add a new taxonomy “outlet” in site.yaml
    taxonomies: [category,tag,month, outlet]
    
  • For each blog or rss page set the following in its frontmatter:
    taxonomy:
      outlet: [rss, blog]   // visible in blog and rss collection
      --or--
      outlet: [rss]         // visible in rss collection
      --or--
      outlet: [blog]        // visible in blog collection
    
  • Define collection as follows:
    content:
      items:
        '@taxonomy.outlet': blog   // Creates collection with blog items
        --or--
        '@taxonomy.outlet': rss    // Creates collection with rss items
      limit: 6
      order:
        by: date
        dir: desc
      pagination: true
      url_taxonomy_filters: true
    

Pagination will be shown correctly.

“Look ma, frontmatter only”

NB:

Didn’t know i need to “define” the variable in the blueprint. I guess blog.yaml?

It’s not required if you use a code editor. It’s only needed when you want to set the value using Admin.

2 Likes

@pamtbaau I was thinking in that option too. :+1: Great

Awesome. That seems to work. Thanks a lot!
Now i only have to find out how i need to change the feed plugin so that it respects these settings.
This way i could publish articles that won’t show up in the RSS feed but only on the website. Great for testing as well.