Access $page etc. from within a helper or Class function?

Hi! Sorry if this is more of a PHP question than a Kirby 3 question - but I’m stuck on this :slight_smile:

I have a plugin, with a helpers.php (required from within index.php). Is there a way to access $page, $kirby and $pages inside the helper function without having to pass them as arguments from within the page template where the helper is used?

…or even better, can I even access these from within the Class function Commentions::queueComment without passing them from the helper?

use sgkirby\Commentions\Commentions;
function commentions( $page, $kirby, $pages ) {
  if ( get('submit') )
    $feedback = Commentions::queueComment( $page, $kirby, $pages );
}

Have you tried the following:

$kirby = kirby();
$page = kirby()->page();
$pages = kirby()->site()->pages();

Thank you @bvdputte ! This was precisely what I was looking/hoping for! …just a tiny typo in the $page line.

This works:

$kirby = kirby();
$page = kirby()->site()->page();
$pages = kirby()->site()->pages();
1 Like

There are also helpers for $page and $pages:

$kirby = kirby();
$page  = page();
$pages = pages();
2 Likes