Grav: @self.children and @self.descendants not filtering out folders

Created on 17 Apr 2016  路  3Comments  路  Source: getgrav/grav

Grav version: 1.0.10.

I have a /news page with subfolers (e.g. /news/2016) which contain pages I want to list in the /news page鈥檚 collection. I鈥檓 using this frontmatter:

title: News
content:
    items:
        '@self.descendants'
    order:
        by: header.publish_date
        dir: desc
    limit: 5
    pagination: true

The resulting page.collection() returns all descendant folders, including folders that do not have a .md file. I would expect that, by default at least, it would only list pages (folders with a .md file).

enhancement

Most helpful comment

Definitely late for a solution, but for anybody curious:
You can add this to filter the posts.
This will mean only files with item.md will be shown as posts.

content:
    filter:
        type: item

All 3 comments

Actually this is expected behavior. A .md file is not a requirement for a page to be considered a page in Grav. For example we commonly use an /user/pages/images folder to store images that are to be shared among other pages. This images/ page is a fully fledged page within Grav even without a .md file. It has a default title (based on the folder name) but no content. By being a fully-fledged page, you can find it like any other page and do stuff with it's media files.

If you have a collection that contains empty folders, you should just filter them out in your Twig by checking if page.file() is null or not.

Definitely late for a solution, but for anybody curious:
You can add this to filter the posts.
This will mean only files with item.md will be shown as posts.

content:
    filter:
        type: item

Never too late @greensam88 you just saved me a BUNCH of time and trouble. I was trying to get my blog posts organised by year folders, similar to what a user was recently trying to do here and everything was fine except the year folders showing up. So glad that is now solved!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ThinkDevStudios picture ThinkDevStudios  路  17Comments

ulilu picture ulilu  路  29Comments

lazzich picture lazzich  路  19Comments

joville picture joville  路  23Comments

ursbraem picture ursbraem  路  29Comments