How can I use isChildOf?

is <?php if($page->isChildOf('fiches')): ?> is the correct syntax ? (like in the example)

I have and error message when I use it :slight_smile:

Catchable fatal error: Argument 1 passed to PageAbstract::isChildOf() must be an instance of Page, string given, called in templates/single-post.php on line 36 and defined in /kirby/core/page.php on line 887

I use this function on other websites without problem, Did I miss something ? (Sure it’s stupid but I can’t find what)

Thank you

Ok, I think I found the problem, I have to do this:

<?php if($page->isChildOf(page('fiches'))): ?>

and it’s working. The example is not really clear as you can believe that the URI string is sufficient, like others kirby functions.

Thanks for pointing this out. This is most likely a bug in Kirby (as that was supposed to work in older Kirby versions). And if it’s not, it is a bug in the docs.

I have added an issue on GitHub.

ha ok, I was wondering because I was quite certain I used it with the string on my portfolio (kirby 2.2) I have to watch it when I update!

1 Like

The syntax from the docs will work in Kirby 2.3.1.

good, thank you very much !