Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Define alternative content until the published date

Started by maxime 6 years ago · 0 replies · 790 views
6 years ago

Hello

I need a page to change it's content at a certain date.
I am thinking to use the publish_date for that, but if the publish date is not reached yet, the page will simply not show. I would like to continue show the present content instead.
How can this be achieved?

EDIT: One solution I found:

TWIG
{% block content %}
    {% if "now"|date('U') < page.header.change_date|date('U') %}
        {% set page = page.find(page.route() ~ '/prev') %}
    {% endif %}
    {% if page is not null %}
            <p>some content...</p>
    {% endif %}
{% endblock %}

And then define the alternative content in a "prev" subfolder.

Note: I can't use the publish_date attribute as the page won't exist in the current context for grav, so instead I use a custom 'change_date' attribute.

Still interested to know if there is a better solution.

Thanks

last edited 10/11/20 by maxime

Suggested topics

Topic Participants Replies Views Activity
General · by themetman, 23 hours ago
2 40 16 hours ago
General · by Hanns Mattes, 1 week ago
0 121 1 week ago
General · by Karmalakas, 1 week ago
2 185 1 week ago
General · by Hanns Mattes, 3 weeks ago
0 235 3 weeks ago
General · by Dima, 4 weeks ago
1 211 4 weeks ago