I have an Events section on my site, and to display upcoming and passed events (entries with a status of pending
or expired
) I manually set the entry in the template:
Where the URL is /events/my-event-title
{% set entry = craft.entries({
section: 'Events',
slug: craft.app.request.segment(2),
status: ['live','pending','expired']
}).one %}
<h1>{{ entry.title }}</h1>
{{ entry.body }}
This works great except when I go to publish a new Event and use the Live Preview. Since the new entry doesn't have a slug yet, the craft.app.request.segment(2)
variable returns null, and so entry
returns the last-published Event entry instead. So all of my template variables are pre-populated with a different entry's content.
How do I set this up so my Live Preview displays blank until I enter content?