Skip to content

Preview Entries in the CP that Aren't Available Publicly #11376

Answered by wsydney76
richhayler asked this question in Q&A
Discussion options

You must be logged in to vote

Found some old stuff that should work for that (at least as a starting point...)

Set up a preview target with a URL format like /internal/sections/pageblock?id={id}

The template can now check whether it is in preview mode and retrieve the entry:

{% requireLogin %}

{% if not craft.app.request.isPreview %}
    {% exit 404 %}
{% endif %}

{% set id = craft.app.request.param('id') %}

{% if not id %}
    {% exit 404 %}
{% endif %}

{# That should fetch an entry regardless of status/provisionalDraft/draft whatever ?? #}
{% set entry = craft.app.entries.getEntryById(id) %}

{% if not entry %}
    {% exit 404 %}
{% endif %}

<h1>{{ entry.title }}</h1>

<h2>ID: {{ entry.id }}</h2>

/Mel

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@brandonkelly
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants