bnomei / kirby3-bolt

Kirby 3 Plugin for a fast Page lookup even in big content trees
https://forum.getkirby.com/t/kirby3-bolt-a-faster-page/23577
MIT License
24 stars 1 forks source link

Bolt working for other things other than the basic use of page('uri') ? #4

Closed carstengrimm closed 2 years ago

carstengrimm commented 2 years ago

I have been wondering if Bolt is also working for pages which are called by other means other than page('uri')

For example i am having a route which is doing a minor task and it's also basically getting a page by the uri in this case a multi-language setup. Anyhow, would i be able to increase the lookup/rendering in this kind of case as well?

        'pattern' => '(?:(^[a-z]{2})//?)?(:all)/(:alpha)',
        'action' => function ($language, $link, $key) {
            if($page = site()->visit($link,$language)){ // as you can see we basically do a similar thing here...
                    $data = [
                        'key' => $key,
                    ];
                    return $page->render($data);
            }
        }
bnomei commented 2 years ago

site->visit can take a pageobject as param. so that should indeed work.

https://github.com/getkirby/kirby/blob/c77ccb82944b5fa0e3a453b4e203bd697e96330d/src/Cms/Site.php#L642

        'pattern' => '(?:(^[a-z]{2})//?)?(:all)/(:alpha)',
        'action' => function ($language, $link, $key) {
            $page = bolt($link);
            if($page = site()->visit($page, $language)){ // as you can see we basically do a similar thing here...
                    $data = [
                        'key' => $key,
                    ];
                    return $page->render($data);
            }
        }