Add "LastEditedBy" or "RevisionCreator" to the entry #7957
-
DescriptionWe currently can add "Last Edited By" in the Control Panel on the entries, but this seems not to be the case when trying to use it easily on the front-end. I see "revisionCreator" being there to use in the table in the CP, but if we query the front-end and dump our entry, there is no trace of who made the last change to the entry. I can see multiple cases where this is really useful. e.g. legal pages within a company environment, where the person doing updates to the page could be a seperate author, so it makes sense to display: This entry has been created on ... by user x and last been edited on .. by user y |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can get the latest revision for an entry via {% if entry.currentRevision %}
<p>
Last edited on {{ entry.currentRevision.dateUpdated|date('short') }}
{% if entry.currentRevision.creator %}
by {{ entry.currentRevision.creator.fullName }}
{% endif %}
</p>
{% endif %} If you are going to do this for more than one entry, you can improve performance by eager-loading the revision + creator data from your initial entry query: {% set entries = craft.entries()
.section('mySectionHandle')
...
.with(['currentRevision.revisionCreator'])
.all() |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer @brandonkelly Couldn't find it in the docs on how to do this decently, also interesting to know you can eager load currentRevision :) |
Beta Was this translation helpful? Give feedback.
You can get the latest revision for an entry via
currentRevision
:If you are going to do this for more than one entry, you can improve performance by eager-loading the revision + creator data from your initial entry query: