I would like to display to user when the post was updated - something like modified_date
. This is different from publish_date
which display when the post was first published.
Does GRAV track when we last modified the post?
I would like to display to user when the post was updated - something like modified_date
. This is different from publish_date
which display when the post was first published.
Does GRAV track when we last modified the post?
Grav does track modified_date. In fact it’s the only date it really can track as that’s the only date that is reliable across different OS Filesystems.
The best approach is to manually set date:
in the page header. This will mean you can get this ‘creation date’ anytime with $page->date()
. Then anytime you update the file, you can get that modified date with $page->modifiedDate()
.
Btw, in Twig parlance, this is page.date()
and page.modifiedDate()
Hi,
So we could write this to have the 10 latest updated pages within the site ?
{% for child in pages.children.nonModular.order('modifiedDate', 'desc').slice(0, 10) %}
<div class="media-object">
{% set showcase_image = child.media.images|first.resize(100,100).url %}
{% if showcase_image %}
<div class="media-object-section">
<img alt="{{ child.title }}" src="{{ showcase_image }}" />
</div>
{% endif %}
<div class="media-object-section">
<h5><a href="{{ child.url }}">{% if child.menu %},{{ child.menu }},{% else %},{{ child.title }},{% endif %}</a></h5>
</div>
</div>
{% endfor %}
Curent result is not the same as what is displayed on admin page for latest changed pages… What did I miss ?
As alternative, trying:
{% set recentnews =
page.collection({
'items': '@root.descendants'
})
.order('modifiedDate', 'desc')
.slice(0,10)
%}
{% for child in recentnews %}
<div class="media-object">
{% set showcase_image = child.media.images|first.resize(100,100).url %}
{% if showcase_image %}
<div class="media-object-section">
<img alt="{{ child.title }}" src="{{ showcase_image }}" />
</div>
{% endif %}
<div class="media-object-section">
<h5><a href="{{ child.url }}">{% if child.menu %},{{ child.menu }},{% else %},{{ child.title }},{% endif %}</a></h5>
</div>
</div>
{% endfor %}
Still does not provide the expected list.
Hi,
It’s what I did at the beginning but it was not working either. Will test it deeper, maybe rsync impacted the datetime of the files too…
Weird, it works now. Maybe I had some cache issues on server or browser side… Sorry for the noise
This worked:
{% set recentnews =
page.collection({
'items': '@root.descendants'
})
.order('modifiedDate', 'desc')
.slice(0,10)
%}
{% for child in recentnews %}
<div class="media-object">
{% set showcase_image = child.media.images|first.resize(100,100).url %}
{% if showcase_image %}
<div class="media-object-section">
<img alt="{{ child.title }}" src="{{ showcase_image }}" />
</div>
{% endif %}
<div class="media-object-section">
<h5><a href="{{ child.url }}">{% if child.menu %},{{ child.menu }},{% else %},{{ child.title }},{% endif %}</a></h5>
</div>
</div>
{% endfor %}
Thanks
@rhukster so we have:
{{ page.header.date }}
<- by setting manually date
in header
{{ page.header.modified_date }}
<- its built in
{{ page.header.publish_date }}
<- its built in but it seems like it is same as date
I can set manually?
Is that correct?
I would say that date
is equal to modified_date
when not set manually and equals to the file’s last modified date on system.
published_date
is really intenteded for future publishing. ie. you create a post today, but set published_date
for next week. it won’t show up until that published_date is passed.