Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Can I include unpublished pages in collections?

Solved by Dimitri Longo View solution

Started by Peter Rankin 8 years ago · 5 replies · 1186 views
8 years ago

I see that in the documentation, collections can be filtered by published or nonPublished. However, I cannot figure out how to include unpublished pages in the first place, and so my collections always end up empty (I want to display titles of upcoming posts with their scheduled publish date).

Is there a way I can include non-published pages in my collection query, either in the header or using Twig? Thanks!

8 years ago Solution

hi @psrankin

you have a method Collection::nonPublished() - Filters the current collection to include only non-published pages

https://learn.getgrav.org/content/collections#multiple-collections

I will do like this :

TWIG
{% for p in page.find('/blog').children.nonpublished('01/01/2014', '01/01/2019').order('date', 'desc') %}
  {{ p.title }}
  {{ p.date|date("d-m-y") }}
{% endfor %}

non tested

I think it will do the job !

last edited 02/27/18 by Dimitri Longo
8 years ago

glad it works ;-)

Could you please mark as solved, thanks

8 years ago

The solved checkbox isn't showing up for me yet (I'm new to Discourse). I assume it has a delay before allowing an answer to be marked as resolved, so I'll check back later. Thanks again!

8 years ago

Thanks for your solution. I still don't see the "solved" checkbox that I'm expecting and can't seem to find any other way to mark your post as the solution. Is something wrong with my account?

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 101 16 hours ago
General · by pamtbaau, 22 hours ago
1 68 21 hours ago
General · by Andy Miller, 1 day ago
0 53 1 day ago
General · by Marcel, 12 months ago
6 361 5 days ago
General · by Duc , 6 days ago
3 49 6 days ago