<p>I had trouble fetching the versions entry data. Things like <code>version.dateUpdated</code> worked, but as soon as I tried to get the data of my custom fields, it would only return the latest data, not the one from the version.</p>

<p>This is what made it work: fetch the version, get the entries version using <code>getVersionById()</code> (<a href="https://craftcms.com/classreference/services/EntryRevisionsService#getVersionById-detail" rel="nofollow noreferrer">docs</a>)</p>

<pre><code>{# Get versions of an entry #}
{% set lastVersions = craft.entryRevisions.getVersionsByEntryId(entry.id, entry.locale) %}

{# Get the version id and fetch the entire entry #}
{% set lastVersionId = lastVersions[0].versionId %}
{% set lastVersionEntry = craft.entryRevisions.getVersionById(lastVersionId) %}
</code></pre>

CC BY-SA 3.0
2017-02-24T19:36:17.057Z
2017-02-24T19:36:17.057Z
medoingthings
<p>Probably something very similar to what Craft does when displaying past entry revisions from a template in the control panel. :)</p>

<p><a href="https://github.com/craftcms/cms/tree/master-v2/src/templates/entries/_revisions.html#L23-L36" rel="nofollow noreferrer">https://github.com/craftcms/cms/tree/master-v2/src/templates/entries/_revisions.html#L23-L36</a></p>

<pre><code>{% if section.enableVersioning %}
    {% set versions = craft.entryRevisions.getVersionsByEntryId(entry.id, entry.locale) %}
    {% if versions %}
        &lt;h6&gt;{{ "Recent Versions"|t }}&lt;/h6&gt;
        &lt;ul class="padded"&gt;
            {% for version in versions %}
                &lt;li&gt;&lt;a{% if entry.getClassHandle() == 'EntryVersion' and version.versionId == versionId %} class="sel"{% endif %} href="{{ url(baseUrl~'versions/'~version.versionId) }}"&gt;
                    {{ "Version {num}"|t({ num: version.num }) }}
                    &lt;span class="light"&gt;{{ version.dateCreated.uiTimestamp() }}, {{ version.creator }}&lt;/span&gt;
                &lt;/a&gt;&lt;/li&gt;
            {% endfor %}
        &lt;/ul&gt;
    {% endif %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-09-22T23:35:46.393Z
2018-02-21T23:44:10.737Z
2018-02-21T23:44:10.737Z
Brad Bell
<p>Is it possible to output content from previous revisions of entries in the twig templates?</p>

<p>I need to do a score comparison between say entry 1 and entry 1.1 to see if the value has increased then output an indicator on the front end to indicate the outcome (Up arrow or down arrow most likely) kind of like a music chart style.</p>

<templating><entries><entry-versions>
Display old entry version content through twig?
# Display old entry version content through twig?

(Asked by: username_0 on 2016-09-22)

Is it possible to output content from previous revisions of entries in the twig templates?

I need to do a score comparison between say entry 1 and entry 1.1 to see if the value has increased then output an indicator on the front end to indicate the outcome (Up arrow or down arrow most likely) kind of like a music chart style.

**Tags:** templating, entries, entry-versions


---

## 2 answers

### Answer by username_1 on 2017-02-24. Score: 1 | Accepted answer

I had trouble fetching the versions entry data. Things like version.dateUpdated worked, but as soon as I tried to get the data of my custom fields, it would only return the latest data, not the one from the version.
This is what made it work: fetch the version, get the entries version using getVersionById() (docs)
{# Get versions of an entry #}
{% set lastVersions = craft.entryRevisions.getVersionsByEntryId(entry.id, entry.locale) %}

{# Get the version id and fetch the entire entry #}
{% set lastVersionId = lastVersions[0].versionId %}
{% set lastVersionEntry = craft.entryRevisions.getVersionById(lastVersionId) %}


---

### Answer by username_2 on 2016-09-22. Score: 1

Probably something very similar to what Craft does when displaying past entry revisions from a template in the control panel. :)
https://github.com/craftcms/cms/tree/master-v2/src/templates/entries/_revisions.html#L23-L36
{% if section.enableVersioning %}
    {% set versions = craft.entryRevisions.getVersionsByEntryId(entry.id, entry.locale) %}
    {% if versions %}
        {{ "Recent Versions"|t }}
        
            {% for version in versions %}
                
                    {{ "Version {num}"|t({ num: version.num }) }}
                    {{ version.dateCreated.uiTimestamp() }}, {{ version.creator }}
                
            {% endfor %}
        
    {% endif %}
{% endif %}


---

