frekw / kirby-modules

A simple module system for http://getkirby.com
MIT License
23 stars 3 forks source link

Hook cache issue #11

Open H-i-red opened 8 years ago

H-i-red commented 8 years ago

Hi man,

Great stuff ! Having an issue, I´m trying to update the field with a hook. The hook works and are updating the text file accordingly, but when I visit the page with the updated field, nothing is shown, although the text file are updated. If i hit save on the page, it deletes the updated field entry from the hook function. If I don´t hit save and clear my cache the page displays the field accordingly..

Text file :

Griddy: 

- 
  title: ""
  subtitle: ""
  type: pager
  options:
    name: North face
    uid: north-face
    uri: projects/north-face
    parent: projects
- 
  title: ""
  subtitle: ""
  type: pager
  options:
    name: Billabong
    uid: billabong
    uri: projects/billabong
    parent: projects

Hook file:

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

        $parent = $page->parent();

        if ($parent->depth() > 0) {

            $griddy = $parent->griddy();

            if ($griddy) {

                $griddy = $griddy->yaml();

                $griddy[] = [
                    'title' => "",
                    'subtitle' => "",
                    'type' => 'pager',
                    'options' => array (
                        'name' => (string)$page->title(),
                        'uid' => (string)$page->uid(),
                        'uri' => (string)$page->uri(),
                        'parent' => (string)$parent->uri()
                    )
                ];

                $parent->update([ 'griddy' => yaml::encode($griddy) ]);
            }
        }
    });
frekw commented 8 years ago

Hi,

Unfortunately (last time I looked – before 2.3 was released) there was no way for this plugin to hook into when the page cache clears due to the file being modified.

Until there's a hook available this can't be fixed without modifying Kirby's core.

H-i-red commented 8 years ago

Oh well, thanks man !!