Can't get draft subpage with findPageOrDraft()

Hi,

I tried to get a subpage with findPageOrDraft() like this:

$site->findPageOrDraft('sydney/proposal-a');

But it return NULL

If I use

$site->draft('sydney/proposal-a');

It works!

findPageOrDraft() is not supposed to return a page or a draft?

Looks like findPageOrDraft only works for the direct children, not with a path.

So if you have a draft with the slug proposal-a in content/_drafts,

dump($site->findPageOrDraft('proposal-a'));

Kirby will find it.

But the doc says findPageOrDraft() takes a “path” in parameter:

$site->findPageOrDraft(string $path)

and to get a direct child there is already the method childrenAndDrafts()

My “proposal-a” subpage is in content/1_sydney/_draft so

$site->findPageOrDraft('proposal-a')

does not works :-/

This is the method:

 public function findPageOrDraft(string $path)
    {
        return $this->children()->find($path) ?? $this->drafts()->find($path);
    }

So it searches in the children, not in the tree.

Ok, thanks @texnixe

Have to agree with @gillesvauvarin though, the docs should not call the argument the path but the uid (?) instead. I was just confused about the same thing, because the docs call it path, when clearly this does not take a full path.

@texnixe this just took me +1h haha. because the docs are not clear here. can confirm it’s only working with direct children. i guess it would be good if they were updated?

:sun_with_face:

Well, but path is correct, because you can pass a path:

$site->findPageOrDraft('notes/exploring-the-universe')

But a complete path still returns NULL if the page is a draft. :confused: Maybe this is a bug? @texnixe

What you can do

  dump($kirby->page('notes/in-the-jungle-of-sumatra'));
1 Like