#draft pages preview

58 messages ยท Page 1 of 1 (latest)

left minnow
#

hello
i want preview pages those are in a draft

fervent star
left minnow
#

hiii @fervent star i tried it but it's preview page if page is published.

#

when page in a draft it's not preview the page.

left minnow
#

heyy @fervent star now it's working ๐Ÿ˜€

#

thanks a lot ๐Ÿ˜€

left minnow
#

heyy @fervent star i have one more query on it

#

i saved page as a draft and i hit slug with baseurl it's showed page insted of 404

left minnow
#

preview: (doc, { locale }) => {
if (doc?.slug) {
return ${process.env.PAYLOAD_PUBLIC_SERVER_URL}/${doc.slug};
}

  return null;
},
#

@fervent star this is my code. preview button redirect to base url and show the page but i don't want to show draft page to end user

#

if i preview page in this way than no any difference between draft and published

fervent star
#

@left minnow this is because you are authorized, if you log out of the cms and revisit the page you'll get 404. The example uses the admin bar plugin which makes this really easy, on the front end click exit preview mode or logout

left minnow
#

hiii @fervent star i logout from the CMS and revisit the page i'm not getting 404 page.

left minnow
#

this is my frontend view

left minnow
#

hello @fervent star i'm waiting for your response.

fervent star
#

hi @left minnow thanks for being patient, let's get to the bottom of this today. I think we are having a miscommunication here so let's take a step back - are you running the preview example or your own code?

left minnow
#

nope @fervent star i review the example so i have a one query about (api/preview) that added in this code preview: doc =>
${process.env.PAYLOAD_PUBLIC_SITE_URL}/api/preview?url=${formatAppURL({ doc })},
},

fervent star
# left minnow preview: (doc, { locale }) => { if (doc?.slug) { return `${process...

Your preview function doesn't look right, it should return return ${process.env.PAYLOAD_PUBLIC_SERVER_URL}/api/preview?url=${doc.slug};

Then make sure you have an api/preview.ts file that you are rendering on the front end, in the demo this is here:

https://github.com/payloadcms/payload/tree/docs/pagination-options/examples/preview/nextjs/pages/api

and to read about how this works, here are the nextjs docs:
https://nextjs.org/docs/advanced-features/preview-mode

You'll see in the payload preview.ts, we are checking for the payloadToken so only authorized users will be able to use preview and view drafts.

Check that you have an api/preview.ts file to begin with, then compare your setup with the links above and I think you should be back on track

left minnow
#

i have to create preview collection?

left minnow
fervent star
#

nope you don't need a preview collection! it will just be a static file that lives on your site

left minnow
#

okay @fervent star

left minnow
#

hii @fervent star i add this preview: (doc) => ${process.env.PAYLOAD_PUBLIC_SERVER_URL}/api/preview?url=${formatAppURL({ doc })},
in my collection and make a preview.ts file in pages/api but i save page as a draft it showing me 404 page.

left minnow
#

and i'm getting console.log(ctx.previewData) true every time if i'm logout from admin panel still i get true

left minnow
cyan patio
#

Hi! @fervent star Would a solution similar to this one work for those of us using the NextJS Server Rendered boilerplate? I am struggling on how to get the API portion for the previews to work with this template

left minnow
#

hello @fervent star can i use preview feature using getsServerside Rendering(SSR).

fervent star
#

Thanks for being patient guys we have had a busy couple weeks here!

@left minnow okay let's figure out what is going wrong here - does PAYLOAD_PUBLIC_SERVER_URL accurately match your front end url? Also, have you booted up the preview example just to see how it should look when it is working? I feel like that might fill in some of the gaps here.

@cyan patio is this the boilerplate you are working with? https://github.com/payloadcms/nextjs-custom-server

fervent star
#

@left minnow @cyan patio yes you can use preview with SSR - to demonstrate I have cloned the nextjs-custom-server repo and added preview mode here: https://github.com/JessChowdhury/nextjs-custom-server-preview

Take a look at this commit, these are the only changes I needed to add to get preview setup: https://github.com/JessChowdhury/nextjs-custom-server-preview/commit/0fa53786ab9244a7a4204b782cc01fc059835bff

And as always the next.js docs on preview can be helpful https://nextjs.org/docs/advanced-features/preview-mode

left minnow
#

heyy @fervent star i successfully implemented preview functionality with SSR

#

thanks a lot for the guide ๐Ÿ™Œ

fervent star
#

absolutely! glad you are setup now! ๐ŸŽ‰

cyan patio
#

Thank you @fervent star!! I will take a look at the repo.

left minnow
#

hello @fervent star one more issue come in preview if i'm duplicate a page and change only pagetitle and slug and save as a draft it showing me 404.

cyan patio
left minnow
#

hii @fervent star i'm facing one issue. page preview not working properly when i duplicate a page.

left minnow
#

and this hook is mandatory?

left minnow
#

and also if i'm duplicate a page and change only slug and then save as a draft preview button not showing original slug

left minnow
#

hello @fervent star i'm waiting for your response

left minnow
fervent star
left minnow
#

hii @fervent star can i know why after change the slug preview button not showing actual slug?

#

and one more thing is that if i'm duplicate a page and save as draft and than refresh the page. preview button showing changed url and redirect to the frontend bt i'm getting 404 page.

#

also i'm use SSR.

fervent star
#

Any chance you could share the repo you are working in?

left minnow
#

l'll inform soon.

#

can i use secret key for NEXT_PRIVATE_REVALIDATION_KEY

left minnow
#

hello @fervent star Due to our company policies I will not be able to share the repo access with you.

Please share any other way-around to identify the issue.

fervent star
#

Could you share a screen recording? I'm having trouble understanding and replicating your issue.

Here you can see when I duplicate a page, then change the slug and save as draft - preview is still working correctly.

left minnow
#

hello @fervent star i'm sharing a screen recording. hope it helps to understand.

fervent star
#

Thank you this helps a lot!

Okay your preview definitely isn't working correctly, could you show me what your preview function looks like in your 'innerpages' collection?

left minnow
#

@fervent star this is my preview function.

left minnow
#

hello @fervent star i'm waiting for your response