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

How do I hide pages in a collection with a published date set to the future?

Started by Muut Archive 9 years ago · 3 replies · 510 views
9 years ago

I don't know why I struggle with things that seem so simple. I have a collection, likely got the code from the Antimatter blog.htm.twig file. I want to have pages appear on the published date.

TWIG
                {% for child in collection %}
                    {% include 'partials/wallpaper_item.html.twig' with {'page':child, 'truncate':true} %}
                {% endfor %}

How can I get this code to hide posts that have publish_date set to the future?

9 years ago

You just need to set the use the .published() function wherever you defined your collection -

TXT
Collection::published() - Filters the current collection to include only published pages

ref: Page collections

9 years ago

Thank you for the help and I did try exactly what you suggested prior to asking here and then my brain melted down I guess. It does work as advertised! What confused me was the published: true switch in page front matter. It over-rides what is in published_date. So now I know, I just have to make sure the published switch is not used. I think what I will do is hide that switch in the blueprint so the customer does not use it. This way only the dates will control whether the posts show or not for this guy.

9 years ago

In case anybody finds this and wants to see the code. I just added .published to the loop.

TWIG
{% for child in collection.published %}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1333 9 years ago
Archive · by Muut Archive, 9 years ago
2 924 9 years ago
Archive · by Muut Archive, 9 years ago
2 4055 9 years ago
Archive · by Muut Archive, 9 years ago
1 2935 9 years ago
Archive · by Muut Archive, 9 years ago
3 1111 9 years ago