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).
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!
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.mdwill be shown as posts.