From 00ac1da29debf3261958de9d55dae802711e936a Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 24 Sep 2014 14:04:49 -0600 Subject: [PATCH] Add modular/regular page filtering to the children() method. Issue #60 --- system/src/Grav/Common/Page/Page.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index f27394f03..1ca0c793f 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1128,14 +1128,25 @@ class Page /** * Returns children of this page. * + * @param bool $modular|null whether or not to return modular children * @return Collection */ - public function children() + public function children($modular = false) { /** @var Pages $pages */ $pages = self::$grav['pages']; + $children = $pages->children($this->path()); - return $pages->children($this->path()); + // Filter out modular pages on regular call + // Filter out non-modular pages when al you want is modular + foreach ($children as $child) { + $is_modular_page = $child->modular(); + if (($modular && !$is_modular_page) || (!$modular && $is_modular_page)) { + $children->remove($child->path()); + } + } + + return $children; } /** @@ -1462,11 +1473,9 @@ class Page if (!empty($parts)) { switch ($parts[0]) { case 'modular': - // FIXME: filter by modular - $results = $this->children(); + $results = $this->children(true); break; case 'children': - // FIXME: filter by non-modular $results = $this->children(); break; }