You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Update Preview for Side Editor * Add mention of beta * Update dev-related info + difference between plans * Fix badges color * Fix broken anchors * Fix bottom of page (usage)
Add the URL generation logic with a `getPreviewPathname` function. The following example is taken from the <ExternalLinkto="https://github.com/strapi/LaunchPad/tree/feat/preview"text="Launchpad"/> Strapi demo application:
Some content types don't need to have a preview if it doesn't make sense, hence the default case returning `null`. A Global single type with some site metadata, for example, will not have a matching front-end page. In these cases, the handler function should return `null`, and the preview UI will not be shown in the admin panel. This is how you enable or disable preview per content type.
Create the complete configuration, expanding the basic configuration created in step 1. with the URL generation logic created in step 2., adding an appropriate handler logic:
204
206
@@ -246,7 +248,7 @@ export default ({ env }) => {
246
248
};
247
249
248
250
```
249
-
#### 4. Set up the front-end preview route
251
+
#### 4. [Front end]Set up the front-end preview route {#4-setup-frontend-route}
250
252
251
253
Setting up the front-end preview route is highly dependent on the framework used for your front-end application.
252
254
@@ -285,33 +287,182 @@ export async function GET(request: Request) {
285
287
}
286
288
```
287
289
288
-
#### 5. Allow the front-end to be embedded
290
+
#### 5. [Front end]Allow the front-end to be embedded {#5-allow-frontend-embed}
289
291
290
292
On the Strapi side, [the `allowedOrigins` configuration parameter](#allowed-origins) allows the admin panel to load the front-end window in an iframe. But allowing the embedding works both ways, so on the front-end side, you also need to allow the window to be embedded in Strapi's admin panel.
291
293
292
294
This requires the front-end application to have its own header directive, the CSP `frame-ancestors` directive. Setting this directive up depends on how your website is built. For instance, setting this up in Next.js requires a middleware configuration (see <ExternalLinkto="https://nextjs.org/docs/app/building-your-application/configuring/content-security-policy"text="Next.js docs"/>).
293
295
296
+
#### 6. [Front end] Detect changes in Strapi and refresh the front-end {#6-refresh-frontend}
297
+
298
+
Strapi emits a `strapiUpdate` message to inform the front end that data has changed.
299
+
300
+
To track this, within your front-end application, add an event listener to listen to events posted through [the `postMessage()` API](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) on the `window` object. The listener needs to filter through messages and react only to Strapi-initiated messages, then refresh the iframe content.
301
+
302
+
With Next.js, the recommended way to refresh the iframe content is with <ExternalLinkto="https://nextjs.org/docs/app/building-your-application/caching#routerrefresh"text="the `router.refresh()` method" />.
In Next.js, [cache persistence](https://nextjs.org/docs/app/building-your-application/caching) may require additional steps. You might need to invalidate the cache by making an API call from the client side to the server, where the revalidation logic will be handled. Please refer to Next.js documentation for details, for instance with the [revalidatePath() method](https://nextjs.org/docs/app/building-your-application/caching#revalidatepath).
OncethePreviewfeatureisproperlysetup, an **Openpreview** buttonisvisibleontherightsideofthe [ContentManager's edit view](/cms/features/content-manager#overview). Clicking it will display the preview of your content as it will appear in your front-end application, but directly within Strapi'stheadminpanel.
When making updates to the content, first save them before clicking on Open Preview again, otherwise your latest updates will be lost. A pop up window will warn you about this behavior.
458
+
Additionally, , youcan:
459
+
- with <GrowthBadge/> and <EnterpriseBadge /> plans, expandthesidepanelbyclickingonthe <Iconname="arrow-line-left"classes="ph-bold"/>buttontomakethePreviewfullscreen,
0 commit comments