-
Someone an Idea if it is possible to write a LivePreviewHook for Astro (without React)? https://payloadcms.com/docs/live-preview/frontend#building-your-own-hook https://docs.astro.build/en/reference/integrations-reference/ somehow i don't know where to start.
SSR is just for testing a boolean variable on the top. best regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I haven't spent much time with either Payload or Astro, so there could be a better way but here's a quick and dirty demo I've come up with while experimenting. Astro components just render down to standard HTML, so you'll just use dom methods to update the content on the page based on the mergedData from the subscribe callback in @payloadcms/live-preview. Any method will depend on how the data is modeled in Payload. I have a Page collection that has a Blocks field. Each block is a component/section a content author can drop on the page (Hero, Rich Text, CTA Banner, etc). A Page.astro component renders the page with all the blocks. A script in it subscribes to the updates from live-preview and manually updates the content based on data attributes in the markup. Here's a rough example that only handles updating text. It also doesn't handle rearranging, removing, or adding blocks.
|
Beta Was this translation helpful? Give feedback.
I haven't spent much time with either Payload or Astro, so there could be a better way but here's a quick and dirty demo I've come up with while experimenting.
Astro components just render down to standard HTML, so you'll just use dom methods to update the content on the page based on the mergedData from the subscribe callback in @payloadcms/live-preview.
Any method will depend on how the data is modeled in Payload. I have a Page collection that has a Blocks field. Each block is a component/section a content author can drop on the page (Hero, Rich Text, CTA Banner, etc).
A Page.astro component renders the page with all the blocks. A script in it subscribes to the updates from live-preview…