Skip to content

Add "LastEditedBy" or "RevisionCreator" to the entry #7957

Answered by brandonkelly
michtio asked this question in Q&A
Discussion options

You must be logged in to vote

You can get the latest revision for an entry via currentRevision:

{% 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()

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #7956 on May 19, 2021 13:40.