Create files from Hook for current page

Is it possible to save files in the content folder of the current page using the page.create:after and page.update:after hooks?

I have tried the following:

$dompdf->stream('expose.pdf');

Data::write('expose.pdf', $dompdf->output());

F::write($this->root().'expose.pdf', $dompdf->output());

file_put_contents($page->diruri().'/expose.pdf', $dompdf->output());

In a page.create:after hook, you have access to $page, so your syntax using $thisdoesn’t make sense, as it refers to the hook, and there is also a slash missing, so try:

F::write($page->root() . '/expose.pdf', $dompdf->output());

Note that in the page.update:after hook the page variable will be $newPage.

Thank you that works now so far, but I get a message when I save the change in the panel.

The message shows me the rendered PDF with the caption: The JSON response could not be parsed.

Then the PDF can be found but is empty.

i am using this:

$dompdf->loadHTML(snippet('pdf/expose',['page' => $newPage]));

Well, I’m not familiar with DomPdf, but according to this SO response, there’s a step missing: php - how to save DOMPDF generated content to file? - Stack Overflow

i’m probably on the wrong track with the snippet. and will try another way to load the content of a template.

Or how to load a snippet without it being rendered?

You have to pass true to return instead of echo:

$html = snippet('pdf/expose', ['page' => $newPage], true);

This is the solution, thank you