Skip to content

[6.x] Allow Live Preview while creating entries - #15648

Open
matsantosz wants to merge 1 commit into
statamic:6.xfrom
matsantosz:live-preview-on-create
Open

matsantosz wants to merge 1 commit into
statamic:6.xfrom
matsantosz:live-preview-on-create

Conversation

@matsantosz

Copy link
Copy Markdown

When you're creating an entry, the Live Preview button doesn't show up. You have to save first and only then can you preview, which is a bit awkward when you're writing a brand new page and just want to see how it looks. On our side this happens all the time with landing pages, and people end up saving throwaway drafts only to get to the preview.

The backend already supports this. The create form gets a livePreviewUrl pointing at collections.entries.preview.create, and that route builds an unsaved entry and returns a token (there's already a test for it in PreviewEntryTest). What was missing was the button itself, plus one bug further down the line: when the preview page loads, EntryRepository::substitute() calls Blink::forget($item->id()), and since a new entry has no id yet, the request fails with a TypeError.

This PR:

  • shows the Live Preview button on the create form by dropping the isCreating check
  • makes substitute() skip the id based substitution when the entry has no id. The entry is still substituted by its URI, which is how the preview request finds it anyway.

I added a test that previews an entry that was never saved and checks that the page renders with its values. Without the fix it fails with the Blink TypeError.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant