Find and get a page by its slug or path


Sorry for my newbie question but I spent hours to get this working:

Within my plugin, I want to get an already created Page by its slug or path?

Like $found = $this->grav->pages->get('myslug')

I am sure it is easy but I can’t find my way…


@Amatiq Have a look at the docs about \Grav\Common\Page\Pages and Plugin Event Hooks

In event, or after, onPagesInitialized, you could try the following two options:

$pages = $this->grav['pages'];
$page = $pages->find('/blog/hero-classes');
$page = $pages->get('/path/to-root/user/pages/');

And, of course, depending on what you want to do and where you are, there are probably more roads that lead to Rome…

1 Like

You are right! I asked for pages too early…

I must ask for pages in onPageInitialized()


1 Like