Hi,
Is it possible to check if a page is a descendant of any page?
<?php if ($page->isDescendantOf('blog')): ?>
Wondering if it’s possible to do something like:
<?php if ($page->isDescendant()): ?>
Hi,
Is it possible to check if a page is a descendant of any page?
<?php if ($page->isDescendantOf('blog')): ?>
Wondering if it’s possible to do something like:
<?php if ($page->isDescendant()): ?>
Maybe the https://getkirby.com/docs/reference/objects/page/depth method is what you’re looking for?
Ha! First time I ever beat you, @texnixe
Seems like there are multiple ways to check if a page has parents…
You can check with $page->parents()->count()
. @thguenther was faster…
Awesome! And congrats @thguenther for the #1 win!
On a side note, I have a collection of custom page methods here: https://github.com/texnixe/k3-pagemethods/blob/master/index.php, that includes a hasParents()
method.
It might be worthwhile to create your own set of methods that you find you need more often and you find missing in Kirby.