Preview field (hook - keep ?)

Hi folks,

A way to hook the “panel.page.keep” ?

Work in progress…

Noticed that there are no way to preview your changes in the panel, so I decided to have a go at it.
For now it´s a preview field containing an iFrame that updates a preview page on click of a button.

Now I am trying to hook that update on "panel.page.keep, so you don´t have to push the button all the time, something like this:

kirby()->hook('panel.page.keep', function($page) {

    $data = $page->content()->toArray();
    $data['title'] = $page->title();
    $data = array_merge($data, $page->changes()->get());

    if ($preview = $page->find('preview')) {
        if ($data) {
            $preview->update($data);
        }
    } else {
        $temp = $page->intendedTemplate();
        $content = $page->content()->toArray();
        $content['title'] = $page->title();
        $uri = $page->uri() .DS. "preview";
        $page->create($uri, $temp, $content);
    }

});

“Open preview” should be renamed to “View page” because it is not a preview…

1 Like

This should most definitely be a core function, to be able to preview your changes before you publish the page. @bastianallgeier

It looks like an early version of my Reveal plugin.

What I mean with early is that I also stared with a preview below the textarea. When I tested it with much content in the textarea the it was hard to see the preview because it was pushed down. Therefor I moved to a splitscreen approach.

Maybe the push hook idea is a good thing, I don’t know but I’m using ajax for it in my plugin. It’s a little slower because it needs to get content from the server side but it’s really fast anyway.