Amatiq
1
Hi!
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…
Thanks!
@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/01.blog/hero-classes');
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
Amatiq
3
You are right! I asked for pages too early…
I must ask for pages in onPageInitialized()
Done!
1 Like