<p>Something like this should work:</p>

<pre><code>{% if craft.request.getParam('draft') == true %}
    {% set drafts = craft.entryRevisions.getDraftsByEntryId(entry.id) %}
    {% if drafts|length %}
        {% set entry = drafts[0] %}
    {% endif %}
{% endif %}

{{ entry.title }}
...
</code></pre>

<p>This is assuming of course that the entry is published at all. If it's disabled then the uri will return 404. In which case you would have to retrieve the entry in some other way. See <a href="https://craftcms.stackexchange.com/questions/6756/loading-an-existing-entries-drafts-in-template-frontend">this answer</a> for an example.</p>

CC BY-SA 3.0
2015-01-30T22:55:59.157Z
Brilliant! I've not used `craft.entryRevisions`, but that very much answers the question. Thank you.
Matt Stein
CC BY-SA 3.0
2016-01-20T23:54:23.220Z
@danherd That's odd. Once the draft has been assigned, I would assume all fields would show the draft version. Are you getting the draft content? Or just seeing this issue with the title?
Douglas McDonald
CC BY-SA 3.0
2015-01-30T22:53:37.950Z
2015-01-30T22:53:37.950Z
2017-04-13T12:51:00.253Z
Douglas McDonald
<p>I've built a help site for a client that pre-releases articles to a select group of beta users. The updated articles (Craft entries) are published as drafts until features make it out of beta and into the main release.</p>

<p>The client has gone and done the clever thing of using the Live Preview URL (<strong>with token</strong>) to share with the limited group of beta users who should only have read-only access to the article:</p>

<pre><code>http://cagedwisdom.com/articles/bloopers?token=3p~rKL53nTcTrO_q1XcWsaBNla5VpzTF
</code></pre>

<p>Since the token is temporary, this link works for a little while and eventually expires and people can no longer review the draft content.</p>

<p><strong>Is there a way to an entry's latest draft?</strong></p>

<p>Let's pretend that I have a the query parameter <code>&amp;draft=true</code> appended to an article URL, and I use that to selectively get the latest draft:</p>

<pre><code>{% if craft.request.getParam('draft') == true %}
    {% set draftEntry = entry.drafts().order('date desc').first() %}
{% endif %}
</code></pre>

<p>Is there a not-imaginary way to do this?</p>

<p>If not, my best ideas are...</p>

<ol>
<li>To create a plugin that'd allow the editor to create a persistent but removable hash for that specific entry that'd allow access to said draft. (So if the article URL is <code>http://cagedwisdom.com/articles/bloopers</code>, the secret draft share URL would be <code>http://cagedwisdom.com/articles/bloopers&amp;draft=Ag4For3Wom8Ot5eeDd9yAf2g</code>.)</li>
<li>Mess with Craft's token expiration values so the shared links last longer.</li>
</ol>

<entries><draft><token>
Can I select the latest draft of a given entry?
# Can I select the latest draft of a given entry?

(Asked by: username_0 on 2015-01-30)

I've built a help site for a client that pre-releases articles to a select group of beta users. The updated articles (Craft entries) are published as drafts until features make it out of beta and into the main release.
The client has gone and done the clever thing of using the Live Preview URL (with token) to share with the limited group of beta users who should only have read-only access to the article:
http://cagedwisdom.com/articles/bloopers?token=3p~rKL53nTcTrO_q1XcWsaBNla5VpzTF

Since the token is temporary, this link works for a little while and eventually expires and people can no longer review the draft content.
Is there a way to an entry's latest draft?
Let's pretend that I have a the query parameter &draft=true appended to an article URL, and I use that to selectively get the latest draft:
{% if craft.request.getParam('draft') == true %}
    {% set draftEntry = entry.drafts().order('date desc').first() %}
{% endif %}

Is there a not-imaginary way to do this?
If not, my best ideas are...

To create a plugin that'd allow the editor to create a persistent but removable hash for that specific entry that'd allow access to said draft. (So if the article URL is http://cagedwisdom.com/articles/bloopers, the secret draft share URL would be http://cagedwisdom.com/articles/bloopers&draft=Ag4For3Wom8Ot5eeDd9yAf2g.)
Mess with Craft's token expiration values so the shared links last longer.

**Tags:** entries, draft, token


---

## 1 answers

### Answer by username_1 on 2015-01-30. Score: 4 | Accepted answer

Something like this should work:
{% if craft.request.getParam('draft') == true %}
    {% set drafts = craft.entryRevisions.getDraftsByEntryId(entry.id) %}
    {% if drafts|length %}
        {% set entry = drafts[0] %}
    {% endif %}
{% endif %}

{{ entry.title }}
...

This is assuming of course that the entry is published at all. If it's disabled then the uri will return 404. In which case you would have to retrieve the entry in some other way. See this answer for an example.

> **Comments:**
> **username_0**: Brilliant! I've not used `craft.entryRevisions`, but that very much answers the question. Thank you.  
> **username_1**: @danherd That's odd. Once the draft has been assigned, I would assume all fields would show the draft version. Are you getting the draft content? Or just seeing this issue with the title?  

---

